问题
programmer
When I set the background-color of the list view belonging to the QComboBox (per QSS), then this QComboBox will no more use the built-in-opticel-look-and feel. Instaed I have to specify all optical settings also per QSS-Stylesheet:
QComboBox QListView {
background-color:white;
border:1px solid black;
}
The list view, which shows the chosable item, displays a checkbox on the left now. This box is checked for those item, chosen on last usage.
How can i hide the column with the checkboxes, so that they will be unvisible and will not be consume any space on the screen?
Thanks in advance...
回答1:
QSS Workaround for a difficult draw topic of QComboBox
If you don't use a QSS block, the QComboBox is drawn with its OS-Look-and-Feel. If you are starting to specify QSS rules some or all subcontrols of the QComboBox begin to lose the OS-Look-and-Feel. In worst case you have to specify all properties in QSS now.
Subject of this article is the choice indicator, drawn by the QStyleViewItem class, a render helper implemented in .../src/gui/widgets/qcombobox_p.h within the QT sources. This functionality seems to be unpossible modifyable by a subclass of QProxyStyle which can be used in other cases for hard layout problems.
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;
}
来源:https://stackoverflow.com/questions/11609337/not-able-to-hide-choice-indicator-of-the-qcombobox