1

I have sub-classed QStyledItemDelegate (just the paint function) and applied to my QTableview along with my custom QAbstractTableModel model for the data. The cells of the Table are drawn correctly, so are when selected, but the color for the Mouse Over is not. What do i miss ? Here is the paint function.. Cells are all black, the selected goes green, but when mouse is over any cell, i dont get the red color.

void  Mydelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
         painter->save();

            if (option.state & QStyle::State_MouseOver) {
                painter->fillRect(option.rect, QColor(Qt::red));
            } else if (option.state & QStyle::State_Selected) {
                painter->fillRect(option.rect, QColor(Qt::green));
             } else painter->fillRect(option.rect, QColor(Qt::black));

            painter->restore();

}
BobR
  • 85
  • 6

1 Answers1

1

Ok, sorry figured it out. Forgot to add mouse tracking in my viewport

ui->table->setMouseTracking(true);

Sorry for that, please mark as Solved (or even delete my post if not useful)

BobR
  • 85
  • 6