2013-07-19 60 views
5

我想通过样式表设计QComboBox,所以我应用了以下qss语法。QComboBox所选项目背景不会反映

QComboBox { 
    border: none; 
    border-radius: 0px; 
background-color: rgb(255, 255, 255); 
color: rgb(0, 0, 0); 
selection-background-color: rgb(0, 85, 255); 
font: 14pt; 
} 

QComboBox:editable { 
    background-color: rgb(255, 255, 255); 
} 

QComboBox:!editable:on, QComboBox::drop-down:editable:on { 
    background-color: rgb(200, 200, 200); 
} 

QComboBox:on { /* shift the text when the popup opens */ 
    padding-top: 3px; 
    padding-left: 4px; 
} 

QComboBox::drop-down { 
width: 0px; 
height:0px; 
border-radius: 0px; 
} 

QComboBox::drop-down:hover 
{ 
    border: none; 
    border-radius: 0px; 
background-color: rgb(0, 170, 255); 
} 

QComboBox QAbstractItemView{ 
background-color: rgb(255, 255, 255); 
    border-radius: 0px; 
color: rgb(0, 0, 0); 
font: 14pt; 
} 

QComboBox QAbstractItemView:item{ 
color: rgb(85, 85, 0); 
background-color: rgb(170, 170, 127); 
selection-background-color: rgb(170, 170, 255); 
selection-color: rgb(85, 0, 127); 
height:40px; 
font: 16pt; 
} 

问题:选择背景色:RGB(170,170,255);在

 QComboBox QAbstractItemView:item{ 
color: rgb(85, 85, 0); 
background-color: rgb(170, 170, 127); 
selection-background-color: rgb(170, 170, 255); <- Not Working 
selection-color: rgb(85, 0, 127); 
height:40px; 
font: 16pt; 
} 

不适用。下拉选中的项目背景不会被反映出来。 请帮我解决这个问题。

回答

4

你试过:

QComboBox QAbstractItemView 
{ 
background-color: rgb(255, 255, 255); 
selection-background-color: rgb(170, 170, 255); <- Should Now Work 
border-radius: 0px; 
color: rgb(0, 0, 0); 
font: 14pt; 
} 
+0

谢谢你的帮助。但我已经离开了Qt工作。 – Jai

+1

@Jai对你来说太糟糕了...... –

+1

@Jacob ..哈哈哈,但不幸的是,现在我要在下个月重新进入Qt – Jai

1

我有同样的问题,对我来说没有任何提出的解决方案我在互联网上找到工作的。最后是这样做的:

QComboBox::item:selected 
{ 
    background-color: rgb(170, 170, 255); 
    color: rgb(0, 0, 0); 
} 

希望这可以帮助其他用户搜索这个。 也许这在最近的版本中发生了变化(我正在使用Qt 5.7)。