QtGui.QComboBox和setStyleSheet-我需要的是,只有选定的值将具有不同的背景颜色

QtGui.QComboBox和setStyleSheet-我需要的是,只有选定的值将具有不同的背景颜色,combobox,pyqt4,stylesheet,Combobox,Pyqt4,Stylesheet,我正在使用SetStyleSheet为我的QtGui.QComboBox设置颜色。 我需要一个特定的选择值将导致所选字段的区域有一个红色的背景颜色,但列表本身应保持白色背景颜色。 我能够创建两个不同的案例,但都有问题,请提供建议 第一个案例+问题: 我成功地将所选值bg颜色更改为红色,但当用户在UI上的其他位置单击时,bg颜色再次变为白色: self.ComboBox.setStyleSheet("selection-background-color:red;") #At the moment

我正在使用SetStyleSheet为我的QtGui.QComboBox设置颜色。 我需要一个特定的选择值将导致所选字段的区域有一个红色的背景颜色,但列表本身应保持白色背景颜色。 我能够创建两个不同的案例,但都有问题,请提供建议

第一个案例+问题: 我成功地将所选值bg颜色更改为红色,但当用户在UI上的其他位置单击时,bg颜色再次变为白色:

self.ComboBox.setStyleSheet("selection-background-color:red;")
#At the moment user clicks somewhere else, the bg is white again. and this is     problematic for me.
第二种情况+问题:

self.ComboBox.setStyleSheet("background-color:red;")') 
#This option causes the whole list to become red, but it remains red as needed and does not turn to bg=white if I click in someplace else in the UI.

感谢您在advanced中的帮助。

我认为您应该试试QSS对象角色——即

QSS

ComboBox::项:已选择
{
背景色:红色;

}

谢谢您的回复,但是,如果我没弄错的话,我的回答和我之前的回答一样:“选择背景色:红色;”-这还不够好,如上所述。请建议。。。非常感谢。