lundi 28 mai 2018

QStyledItemDelegate stuck in hover state when leaving a QListView

I'm stuck at trying to remove a hover state from a QStyledItemDelegate when I leave a QListview .

I check the hover 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
     }
 }

Now when I leave the view the paint method is either not called or option.state is still in mouse over state.

Then I tried to implement the leaveEvent in my QListView to call update.

void MyListView::leaveEvent(QEvent *event)
{
   update();
   QListView::leaveEvent(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 not be in mouse over state when the cursor leaves the listview ?

Aucun commentaire:

Enregistrer un commentaire