2013-07-19 68 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)。