作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我继承了 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/
我是一名优秀的程序员,十分优秀!