使用样式表在QT中更改树视图选择颜色

时间:2014-08-21 19:41:49

标签: qt qtstylesheets

我正在尝试更改树元素选择的颜色。我已经能够用

成功地改变大部分颜色
QWidget:item:selected {
    background-color: red;
}

但是在所选元素的左侧还有默认的蓝色突出显示,并且想要更改它。如果您有任何建议,我们将不胜感激。

2 个答案:

答案 0 :(得分:2)

这对我有用:

QTreeView::branch:selected {
  background-color: yellow;
}

答案 1 :(得分:1)

使用Qt Style Sheets Examples中的代码:

QTreeView::branch  {
        background: palette(base);
}

QTreeView::branch:has-siblings:!adjoins-item  {
        background: cyan;
}

QTreeView::branch:has-siblings:adjoins-item  {
        background: red;
}

QTreeView::branch:!has-children:!has-siblings:adjoins-item  {
        background: blue;
}

QTreeView::branch:closed:has-children:has-siblings  {
        background: pink;
}

QTreeView::branch:has-children:!has-siblings:closed  {
        background: gray;
}

QTreeView::branch:open:has-children:has-siblings  {
        background: magenta;
}

QTreeView::branch:open:has-children:!has-siblings  {
        background: green;
}
相关问题