QSS QComboBox の難しい描画トピックの回避策
QSS ブロックを使用しない場合、QComboBox は OS-Look-and-Feel で描画されます。QSS ルールの指定を開始すると、QComboBox の一部またはすべてのサブコントロールで OS ルック アンド フィールが失われ始めます。最悪の場合、QSS ですべてのプロパティを指定する必要があります。
この記事の主題は、QT ソース内の .../src/gui/widgets/qcombobox_p.h に実装されているレンダー ヘルパーである QStyleViewItem クラスによって描画される選択インジケーターです。この機能は、他のケースでハード レイアウトの問題に使用できる QProxyStyle のサブクラスでは変更できないようです。
ただし、適切に選択された一連のルールを指定することで、QSS で解決策を見つけました。
/* 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;
}