QStyledItemDelegate does not highlight with the rest of the row on mouse-over
-
I set up a delegate for a column in a QTableView and I'd like it to draw an icon when the mouse hovers somewhere over its row.
Having it react to a mouse-over on the delegate itself is easy:
void MyDelegate::paint(QPainter *in_p_painter, const QStyleOptionViewItem &in_option, const QModelIndex &in_index) const { QStyledItemDelegate::paint(in_p_painter, in_option, in_index); if (in_option.state & QStyle::State_MouseOver) { // Draw the icon m_add_icon.paint(in_p_painter, in_option.rect, Qt::AlignCenter, QIcon::Normal); } }
By trying this, I figured it would be better to show the icon when the user hovers anywhere on the row, not just the cell with the delegate.
Unfortunately, the delegate does not highlight with the rest of the row on mouse-over, so I can't poll any QStyle flags noticing me of a highlighting:I see two solutions for this:
a) Make sure the column with the delegate highlights with the rest of the row and poll the highlight flags
b) Find the highlighting-state of a neighboring cell in the same row and react to thatI'd prefer solution a), obviously. But maybe there's an even better way. Any ideas?
-
Are you sure that the cell is enabled? Otherwise I don't see why the delegate should not be called when the whole line is hovered.
-
@Christian-Ehrlicher Yes, I don't know why it shouldn't be enabled and it also reacts to the editor event.