В результате остановился на таком решении:
C++ (Qt)
class RowHoverDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
RowHoverDelegate(QTableView *tableView);
void paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const override;
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
private:
QTableView *m_tableView;
int m_hoveredRow;
};
C++ (Qt)
RowHoverDelegate::RowHoverDelegate(QTableView *tableWidget)
: QStyledItemDelegate(tableWidget)
, m_tableView(tableWidget)
, m_hoveredRow(-1)
{
m_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
m_tableView->setMouseTracking(true);
m_tableView->installEventFilter(this);
m_tableView->viewport()->installEventFilter(this);
}
void RowHoverDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QStyleOptionViewItem opt = option;
if(index.row() == m_hoveredRow) {
opt.state |= QStyle::State_MouseOver;
} else {
opt.state &= ~QStyle::State_MouseOver;
}
QStyledItemDelegate::paint(painter, opt, index);
}
bool RowHoverDelegate::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseMove) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
m_hoveredRow = m_tableView->rowAt(mouseEvent->pos().y());
} else if (event->type() == QEvent::Leave) {
m_hoveredRow = -1;
}
return QObject::eventFilter(obj, event);
}