windows - QTableView:如何将鼠标悬停在整行上?

标签 windows qt hover row qtableview

我继承了 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);
}

    ...
}

...但我不知道如何悬停整行。有人可以帮我提供示例代码吗?

最佳答案

有两种方法..

1) You can use delegates to draw the row background...
You will need to set the row to highlight in the delegate and based on that, do the highlighting.

2) Catch the signal of current row. Iterate over the items in that row and set background for each item.

你也可以试试样式表:

QTableView::item:hover {
    background-color: #D3F1FC;
}        

希望对大家有用。

关于windows - QTableView:如何将鼠标悬停在整行上?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14245365/

相关文章:

c++ - 如何使用包装在 ComPtr 中的 Direct3D 11 指针来获取 11.1 接口(interface)?

c - 在 Windows xp/7 中访问并行端口的特殊驱动程序

windows - 标题名称中的 taskkill 窗口空格

c++ - 阻止 Qt 翻译动态属性

jquery - setInterval 和 setTimeout 在悬停时停止在一起

html - 增加悬停链接的字体大小会改变背景颜色的大小,如何阻止这种情况?

c++ - RegOpenKeyEx 的奇怪行为

python - 将 QMimeData 粘贴到另一个窗口的 QTextEdit

c++ - 如何将 QAction 添加到 QToolBar 中的特定位置

css - woocommerce 最近的产品悬停颜色