c++ - 从 "fusion"样式的 QTreeView 中删除蓝色选择

标签 c++ qt qtreeview qtstylesheets

我有一个 QTreeView 带有定义选择的样式表。但是,当我使用“融合”样式时,装饰上方多了一个蓝色选择矩形:

blue selection rectangle

我试过在样式表中使用 show-decoration-selected: 0; 以及设置 setAllColumnsShowFocus(false);,但无法获取它会消失。

是否有某种方法可以禁用或重新设计覆盖装饰器的选择部分?

作为引用,这里是样式表:

QTreeView, QListView, QToolBar, QTableView
{
    show-decoration-selected: 0;
    background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0,
                            stop: 0 #797979, stop: 0.2 #CCCCCC,
                            stop: 1.0 #FFFFFF);
    alternate-background-color: #333333;
    background-image: url(:/metal_scratched);
    outline: 0; /* removes focus rectangle*/
}

QTreeView::section, QListView::section, QToolBar::section, QTableView::section
{
    border: 1px solid black;
}

QTreeView::item:hover:enabled, QListView::item:hover:enabled, QToolBar::item:hover:enabled, QTableView::item:hover:enabled
{
    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                            stop: 0 transparent, stop: 0.4 rgba(150,150,150,0.5),
                            stop: 0.5 rgba(125,125,125,0.5), stop: 1.0 transparent);
    border-color: #B0B0B0;
}

QTreeView::item:hover:!enabled, QListView:disabled:hover, QToolBar:disabled:hover, QTableView:disabled:hover
{
 /* don't highlight */
}

QTreeView::item:selected, QListView::item:selected, QToolBar::item:selected, QTableView::item:selected
{
    background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
                            stop: 0 transparent, stop: 0.4 rgba(75,75,75,0.5),
                            stop: 0.5 rgba(50,50,50,0.5), stop: 1.0 transparent);
    border-color: #5A5A5A;
    color: white;
}

最佳答案

可以通过覆盖样式表中的默认选择颜色来移除蓝色工件。保持其他一切不变(重要的是,继续使用 QTreeView::item:selected 定义新的选择颜色),添加以下属性将消除不需要的行为。

QTreeView
{
    // everything else the same
    selection-background-color: transparent;
}

关于c++ - 从 "fusion"样式的 QTreeView 中删除蓝色选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28366805/

相关文章:

c++ - 错误 : expected constructor, 析构函数,或 ';' token 之前的类型转换?

c++ - 我应该在 boost 几何函数中使用什么

c++ - 为什么 QTreeView 不显示数据?

c++ - 如果我没有显式实例化 g++(使用 -fno-implicit-templates)从哪里获取模板定义?

c++ - 如何从qt中的单选按钮获取值?

qt - qt中的按键事件

c++ - 使用 Boost 库 Qt C++ 更新翻译文件

c++ - 如何准确知道用户何时展开 QTreeView 项目?

c++ - 如果 QTreeView 项没有子项,则禁用 QAction

c++ - 为什么这里会出现 "the adress of bool will always evaluate as true"?