Search code examples
qtdelegatesmouseoverqstyleditemdelegateqstyle

Why does delegate not recognize the state mouseOver?


I created a delegate and need to recognize mouseOver state to build an effect. But it does not work. When I my table appears, the output is like this enter image description here

When i move the mouse over the table, the output is like this enter image description here

I don't see the state MouseOver. How can I recognize it?

void TableDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const
{
  qDebug() << option.state;
  if ( option.state == QStyle::State_MouseOver )
  {
     painter->fillRect( option.rect, QColor( 249, 126, 18 ) );
  }
}

Solution

  • OK, it takes me a while to find out that i need to add this line to my myTable.cpp

    myTable->viewport()->setAttribute( Qt::WA_Hover );