QTreeView Item highlight problem



  • All,

    I have implemented a class that inherits from QTreeView. I am having a problem where occasionally if I CTRL+Click some items, and then click within the Tree widget, but not on an item, or I click an item without CTRL+Click I one of the originally selected items remains highlighted, but not the clicked highlighted, more like the mouse hover highlighted.

    I have overwritten the following routines

    void selectionChanged ( const QItemSelection & selected, const QItemSelection & deselected )
    void mousePressEvent ( QMouseEvent * event )

    Both of these overwritten routines delegate to the QTreeView parent, but then check what is selected in order to emit certain signals to enable/disable buttons on the UI.

    What is the signal or event or state that gives the item the highlighted look?



  • As I test this more it looks like I can get the strange highlighting only if I move the mouse while the button is pressed.



  • I have stepped into the qtreeview.cpp code and it looks like for some reason the QTreeViewPrivate object thinks that this index is still assigned to the "hover" object within the tree. Does anyone know how I can clear the "hover" member of the QTreeViewPrivate object?



  • This is probably not the best solution to this problem, but in my overwritten mousePressEvent I am calling the QTreeView::mouseMoveEvent which causes the hover object to be cleared out. This has resolved my problem, but it feels like too much of a hack, so I would appriciate anyone's feedback.


Log in to reply
 

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