plover
plover

Reputation: 439

ListViewItem stuck in mouse over state when the mouse leaves a QListView

I'm trying to remove a mouse over state from an item when the mouse cursors leaves a QListview.

I check the mouse over state in the QStyledItemDelegate as follows:

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

Then I implemented the leaveEvent in my QListView to call update.

void MyListView::leaveEvent(QEvent *event)
{
   // update();  
   QListView::leaveEvent(event);
   update();   // Same result if update() called before or after QListView::leaveEvent 
}

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 not be in mouse over state when the cursor leaves the listview ?

I'm using Qt 5.6 and I've tested this on Centos 7 and Fedora 27 and 28.

Upvotes: 0

Views: 535

Answers (1)

plover
plover

Reputation: 439

This seems to be a bug in the QT 5.6 version. I upgraded the QT version to 5.11 and that solved the problem. There is no need to implement the QListView::leaveEvent after the upgrade.

I also tested the code on QT 5.10 and it works fine there.

Upvotes: 1

Related Questions