我对 QTableView、QAbstractTableModel 和 QItemDelegate 进行了子类化。现在我能够在鼠标悬停时悬停在单个单元格上:
void SchedulerDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
...
if(option.showDecorationSelected &&(option.state & QStyle::State_Selected))
{
QColor color(255,255,130,100);
QColor colorEnd(255,255,50,150);
QLinearGradient gradient(option.rect.topLeft(),option.rect.bottomRight());
gradient.setColorAt(0,color);
gradient.setColorAt(1,colorEnd);
QBrush brush(gradient);
painter->fillRect(option.rect,brush);
}
...
}
...但我不知道如何悬停整行。有人能帮我提供示例代码吗?