Failed to hide Choice-Indicator QComboBox

programmer

When I set the background color of the list owned by QComboBox (for QSS), then that QComboBox will no longer use the built-in optical look and feel. Instaed I have to specify all the optical settings also in the QSS-Stylesheet:

QComboBox QListView { background-color:white; border:1px solid black; } 

In the list view, which displays the chosable item, the checkbox on the left is now displayed. This check box is selected for this item selected the last time it was used.

How can I hide a column using checkboxes so that they are invisible and will not consume any screen space?

Thanks in advance...

+1
source share
1 answer

QSS workaround for complex theme for QComboBox

If you are not using a QSS block, the QComboBox is drawn using OS-Look-and-Feel. If you start specifying QSS rules, some or all of the QComboBox subcontrollers begin to lose OS-Look-and-Feel. In the worst case, you should specify all the properties in QSS now.

The topic of this article is a selection indicator drawn by the QStyleViewItem class, a visualization assistant implemented in ... / src / gui / widgets / qcombobox _p.h in QT sources. This functionality seems impossible to modify the QProxyStyle subclass, which can be used in other cases for tough layout tasks.

However, I found a solution in QSS by specifying a well-chosen set of rules:

 /* Background color of popup-list.*/ QComboBox QListView{ background-color:white; border:1px solid gray; } /* Needed to complete the rule set. */ QComboBox::item:alternate { background: white; } /* Color of the selected list item. */ QComboBox::item:selected { border: 1px solid transparent; background:yellow; } /* Indicator will shine through the label text if you don't make it hidden. */ QComboBox::indicator{ background-color:transparent; selection-background-color:transparent; color:transparent; selection-color:transparent; } 
+3
source

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


All Articles