【问题标题】:Why does my stylesheet apply to one qtreewidget, but not another?为什么我的样式表适用于一个 qtreewidget,而不适用于另一个?
【发布时间】:2013-08-06 20:36:51
【问题描述】:

我有两个 QTreeWidget,以及一个应用于两者的样式表(通过一个共同的祖先):

styleSheet += QString("QWidget:!active { ");
styleSheet += QString("  selection-background-color: %1; ").arg(inactiveHighlight.name());
styleSheet += QString("  selection-color: %1;            ").arg(inactiveHighlightText.name());
styleSheet += QString("}\n");
styleSheet += QString("QWidget:active { ");
styleSheet += QString("  selection-background-color: %1; ").arg(activeHighlight.name());
styleSheet += QString("  selection-color: %1;            ").arg(activeHighlightText.name());
styleSheet += QString("}\n");

第一棵树应用了选择颜色,另一棵树没有。

我使用的是 Qt 4.8.5,并且从 Qt 4.6.3 开始就遇到了这个问题。

【问题讨论】:

    标签: qt user-interface qt4 stylesheet


    【解决方案1】:

    这样做的原因是一个 QTreeWidget 附加了一个编辑委托,而另一个没有。这导致 QTreeWidget 的行的绘制由不同的对象绘制。一种尊重“旧”CSS 方式,一种遵循“新”CSS 方式,如下面的链接所述。

    QStyledItemDelegate – Styling Item views

    因此样式也需要类似于:

    styleSheet += QString("QTreeView::item:selected:active { background-color: #123456; }");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-07
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 2019-04-28
      相关资源
      最近更新 更多