Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ “从QTreeView中删除蓝色选择”;融合“;风格_C++_Qt_Qtreeview_Qtstylesheets - Fatal编程技术网

C++ “从QTreeView中删除蓝色选择”;融合“;风格

C++ “从QTreeView中删除蓝色选择”;融合“;风格,c++,qt,qtreeview,qtstylesheets,C++,Qt,Qtreeview,Qtstylesheets,我有一个QTreeView,带有定义选择的样式表。但是,当我使用“fusion”样式时,装饰上方还有一个额外的蓝色选择矩形: 我已尝试使用显示所选装饰:0以及设置setAllColumnsShowFocus(false),但无法使其消失 有没有办法禁用或重新设置覆盖装饰器的选择部分的样式 以下是样式表供参考: QTreeView, QListView, QToolBar, QTableView { show-decoration-selected: 0; background:

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

我已尝试使用
显示所选装饰: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;
}

在进一步的检查中,我发现真正实现这一点的唯一方法是设置Qt应用程序的调色板

这样,

QApplication app(argc, argv);
app.setStyle(QStyleFactory::create("fusion"));
QPalette palette;
palette.setColor(QPalette::Highlight, QColor(your-color));

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

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

不幸的是,设置调色板颜色并不能移除蓝色工件。Qt样式并不广泛使用选项板,并且通常不能很好地与样式表配合使用。@NicolasHolthaus,除了,我目前正在使用样式表,这是我能够成功消除所有小部件中蓝色突出显示的唯一方法。我给出的解决方案也被GitHub上的一些样式表回购使用。确切地说,我是从QDarkStyle回购协议中获得的。我能说的是,它并没有解决我的应用程序中的问题,但“selection background color”属性解决了这个问题。也许我们使用的是不同的Qt版本(我使用的是5.4.2),或者问题的根本原因并不完全相同。看起来
QDarkStyle
是用python编写的。我使用C++ Qt,所以可能也有差异。我也用QT和C++一起使用。我的具体问题是QMainWindow菜单栏子菜单。所有QS都不适用于这些。今天晚些时候我将再次尝试。