Remove the blue fusion selection from QTreeView

I have a QTreeView with a list of styles that determines the choice. However, when I use the "merge" style, there is an additional blue selection rectangle above the decoration:

blue selection rectangle

I tried using show-decoration-selected: 0; in the stylesheet, and also set setAllColumnsShowFocus(false); but I can't get him to leave.

Is there a way to disable or reinstall the part of the selection that covers the decorator?

For reference, here is the stylesheet:

 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; } 
+5
source share
2 answers

The blue artifact can be removed by overriding the default selection color in the stylesheet. Leaving everything else the same (important, continuing to define the new highlight color with QTreeView::item:selected ), adding the following property will remove the unwanted behavior.

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

In a further review, I found that the only way to achieve this is to set the palette of your Qt application.

Thus,

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

Source: https://habr.com/ru/post/1212806/


All Articles