gpt4 book ai didi

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

转载 作者:可可西里 更新时间:2023-11-01 09:34:44 25 4
gpt4 key购买 nike

我继承了 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com