Important: Please read the Qt Code of Conduct -

Item stuck in mouseover state when the mouse leaves a QListView

  • Hi I posted this question on stackoverflow with no response so I'm going to try here.

    When the mouse cursors leaves a QListview, the last item that the mouse was over is sometimes still stuck in mouse over state. This usually happens if I move the mouse to the parent widget or another QListview that is above it.

    My QListView has a QStyledItemDelegate that draws the item and I check the mouse over state in the paint method in the following way :

    void MyDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
        if( option.state & QStyle::State_MouseOver)
            // Paint in MouseOver state
            // Paint normally

    Then I implemented the leaveEvent in my QListView to call update so the view is updated when the mouse leave the view.

    void MyListView::leaveEvent(QEvent *event)

    This does call the paint method of the delegate on leave but doesn't change the hover state of the item last hovered over in the QListView.

    Is there a way to force the delegate to repaint and the last item not be in mouse over state when the cursor leaves the listview ?

  • @plover
    Is it worth a try to see whether it works right if in your override you call the base leaveEvent() before the update()`?

  • I've already tried that. I've also tried to delay the update() by using a QTimer but the results are the same.

  • Lifetime Qt Champion


    You should also tell:

    • Which version of Qt
    • Which OS

  • @SGaist
    I'm currently using Qt 5.6, and I've tested this on centos 7, fedora 27 and 28.

  • I updated the QT version to 5.11 and the problem goes away. No need to implement the leaveEvent of the QListView.
    Tested also with 5.10 and it worked there as well.