简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM