Along with setting up uniformRowHeights in your QTreeView is what I would like to try.
There are several ways to do this, I like to use Qt signals / slots, so we will change the height using a custom QAbstractItemModel on a QTreeView . This custom model will be connected to the selectionChanged signal from the QItemSelectionModel your QTreeView . The sample code / snippets works with one selection mode, but you can easily change it to handle multiple selected lines.
Step 1 - Creating a Custom Model with a Selection Slot
Create your own model class, which comes from QAbstractItemModel and make sure you create a slot, for example:
Q_SLOTS: void onSelectionChanged( const QItemSelection&, const QItemSelection& );
Inside the model class, add the following snippets / methods.
void MyModelClass::onSelectionChanged( const QItemSelection& selected, const QItemSelection& deselected ) { if( !selected.empty() ) {
Step 2 - Connect the selection changes to your model
Inside the initialization of your QTreeView create your own model and do the following:
MyTreeView::MyTreeView( QWidget* parent ) : QWidget( parent ) { ... MyModelClass* model = new MyModelClass(); setModel( model ); setSelectionMode( QAbstractItemView::SingleSelection ); setSelectionBehavior( QAbstractItemView::SelectRows ); connect ( selectionModel(), SIGNAL( selectionChanged(const QItemSelection&, const QItemSelection&) ), model, SLOT( onSelectionChanged(const QItemSelection&, const QItemSelection&) ) ); }
I am sure there are several ways to do this, i.e. pass the QItemSelectionModel directly to your QAbstractItemModel , but again I prefer to use signals / slots and save the selection in the model.
Hope this helps.