Do understand that the delegate is used to draw each item in the view. In QTableView one item is same as one cell. When the view paints itself it draws those items from top to bottom, and left to right. With your implementation you are painting the mouse over effect outside the rectangle that current item occupies. When next item in the row is painted it will paint itself over the mouseover effect. Maybe this the reason?
I think you should check the mouseover status by manually instead of trusting the style option's state information as it is valid only for the current item/cell.
Maybe something like this:
if( rowRect.contains( mousePosition ) ) // check if mouse cursor is on top of current row
{
// paint mouseover effect only for current item
painter
->fillRect
(option.
rect,
QColor(191,
205,
228));
}
QPoint mousePosition = view->mapFromGlobal( QCursor::pos() );
if( rowRect.contains( mousePosition ) ) // check if mouse cursor is on top of current row
{
// paint mouseover effect only for current item
painter->fillRect(option.rect, QColor(191, 205, 228));
}
To copy to clipboard, switch view to plain text mode
Bookmarks