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();
}