QTreeView selection not updating until mouse enters



  • I have a class that inherits QTreeView. That class has a slot to select an entry in the model by name. The intention is that a user clicks on an object in a different window and the corresponding entry in the tree view is selected. I use the default selectionModel and select the entry. I even call scrollTo to make sure the view window is scrolled to that entry. I then call update(). However, the tree view doesn't actually show the selection until the mouse enters the viewport. The next selection that is made after the mouse leaves the viewport will update the tree view, but any selections after that will not update the tree view until the mouse once again enters the viewport. I can force the desired behavior if I explicitly call hide() and then show() instead of update() but that is an ugly hack.

    Thanks in advance,
    -Harry



  • The selection is usually updated immediately. How do you call the respective slots?



  • I connect the slot to a corresponding signal emitted by another widget. The signal is obviously getting emitted and qDebug statements show that the slot is indeed being called.

    From the slot:

    @this->selectionModel()->select(sortedIndex, QItemSelectionModel::ClearAndSelect);
    this->scrollTo(sortedIndex);@

    One thing of interest is that I have sorting enabled in the tree view. I don't know if that could have an effect. I am definitely selecting the correct index because as soon as I move the mouse over the tree view window the correct entry is selected.



  • That's really strange. The code looks perfectly ok to me. Can you create a small, complete test case?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.