如何更改 QComboBox 中未选中项的颜色? (样式sheet)
How to change the color of non-selected item in QComboBox ? (Style sheet)
我想改变Qt中QComboBox的样式。我想将未选中项目的文本(FR、ES、IT、..)完全放入白色,因为它们是黑色的。
这是使用的样式 sheet :
QComboBox
{
background-color:black;
border-color:white;
color:red;
border-width: 1px;
border-style: solid;
padding: 1px 0px 1px 3px;
selection-color:white;
}
要更改组合框项目的样式,您可以设置内部 QAbstractItemView 的样式
示例:
QComboBox QAbstractItemView {
background-color: rgb(41,41,41);
color: white;
selection-background-color: rgb(88, 88, 88);
selection-color: rgb(200, 200, 200);
}
虽然 dydil 的答案可以正常工作,但如果您想通过选择器和伪状态进一步控制 QComboBox
,您将需要使用 QComboBox::setView()
.
一个使用伪状态的例子:
QComboBox QAbstractItemView::item{color: blue;}
QComboBox QAbstractItemView::item:hover{color: red;}
QComboBox QAbstractItemView::item:selected{background-color: green;}
然后添加视图:
myComboBox->setView(new QListView);
我想改变Qt中QComboBox的样式。我想将未选中项目的文本(FR、ES、IT、..)完全放入白色,因为它们是黑色的。
这是使用的样式 sheet :
QComboBox
{
background-color:black;
border-color:white;
color:red;
border-width: 1px;
border-style: solid;
padding: 1px 0px 1px 3px;
selection-color:white;
}
要更改组合框项目的样式,您可以设置内部 QAbstractItemView 的样式
示例:
QComboBox QAbstractItemView {
background-color: rgb(41,41,41);
color: white;
selection-background-color: rgb(88, 88, 88);
selection-color: rgb(200, 200, 200);
}
虽然 dydil 的答案可以正常工作,但如果您想通过选择器和伪状态进一步控制 QComboBox
,您将需要使用 QComboBox::setView()
.
一个使用伪状态的例子:
QComboBox QAbstractItemView::item{color: blue;}
QComboBox QAbstractItemView::item:hover{color: red;}
QComboBox QAbstractItemView::item:selected{background-color: green;}
然后添加视图:
myComboBox->setView(new QListView);