c++ - Qt C++ QStyledItemDelegate 子类 - 鼠标悬停在油漆上
问题描述
我已经对数据进行了子分类(只是绘制功能)并与我的自定义模型一起QStyledItemDelegate
应用于我的数据。表格的单元格绘制正确,选中时也是如此,但鼠标悬停的颜色不是。我想念什么?这是绘画功能.. 单元格都是黑色的,选定的变为绿色,但是当鼠标悬停在任何单元格上时,我没有得到红色。QTableview
QAbstractTableModel
void Mydelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
painter->save();
if (option.state & QStyle::State_MouseOver) {
painter->fillRect(option.rect, QColor(Qt::red));
} else if (option.state & QStyle::State_Selected) {
painter->fillRect(option.rect, QColor(Qt::green));
} else painter->fillRect(option.rect, QColor(Qt::black));
painter->restore();
}
解决方案
好的,抱歉想通了。忘记在我的视口中添加鼠标跟踪
ui->table->setMouseTracking(true);
抱歉,请标记为已解决(如果没有用,甚至删除我的帖子)
推荐阅读
- javascript - jQuery巨型菜单添加/删除父菜单项上的类
- apache-spark - 在 Databricks 中添加“com.crealytics.spark.excel”的替代方法
- javascript - > 错误:架构无效:数据应等于 ajv JSON 架构中的常量
- tomcat - 无法使用本地主机打开 Jira
- arrays - 在索引处查找对象值并使用 swift 将其存储在不同的数组中
- python - 如何遍历 django 模板中的列表
- r - 在 nlme 中初始化相关结构时出错
- powershell - 递归迭代文件
- python - 查找百分比值数字和/或包含任意数量字符串的左括号时要拆分的 pandas 列
- oracle - 与在线 md5 生成器相比,MD5 oracle 函数提供不同的输出