【问题标题】:Setting a particular cell with a color (red/green /yellow) on Qtableview在 Qtableview 上设置具有颜色(红色/绿色/黄色)的特定单元格
【发布时间】:2017-12-07 07:47:57
【问题描述】:

我一直在寻找如何在 qtableview 的特定单元格上设置颜色。 目前,我正在使用 qt 示例冻结列来查看如何在特定单元格上设置颜色。
我在论坛上搜索如何告诉使用 qitemdelegate 或 qstyleitemdelegate 绘制背景或前景单元格,但无效。

有人可以启发我或展示我应该如何去做的代码示例。

【问题讨论】:

    标签: c++ qt qtableview qitemdelegate qstyleditemdelegate


    【解决方案1】:

    我能想到的最快方法是使用标准项的setData 方法:

    QStandardItemModel model;
    QStandardItem item;
    item.setData(QBrush(Qt::gray), Qt::BackgroundColorRole); //background color
    model.setItem(x, y, &item);
    

    在本例中,您设置了背景颜色。描述了不同的角色(作为第二个参数传递)here

    【讨论】:

    • 哇,感谢您的及时回复,我设法设置了我想要的颜色。非常感谢。
    猜你喜欢
    • 2021-07-07
    • 2011-05-08
    • 1970-01-01
    • 2018-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-23
    • 1970-01-01
    相关资源
    最近更新 更多