【问题标题】:Qt C++ QStyledItemDelegate subclass - Mouse over paintQt C++ QStyledItemDelegate 子类 - 鼠标悬停在油漆上
【发布时间】:2020-07-20 23:30:11
【问题描述】:

我已经对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();

}

【问题讨论】:

    标签: c++ qt qstyleditemdelegate


    【解决方案1】:

    好的,抱歉,想通了。忘记在我的视口中添加鼠标跟踪

    ui->table->setMouseTracking(true);
    

    抱歉,请标记为已解决(如果没有用,甚至删除我的帖子)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-14
      • 2010-10-20
      • 2016-01-27
      • 2021-11-28
      • 2011-08-04
      • 2018-09-03
      • 2019-01-22
      • 1970-01-01
      相关资源
      最近更新 更多