cbo.setStyleSheet('background-color: rgb(205,92,92)')
这会为整个组合框添加背景。我想为组合框的某些行添加背景颜色。 谢谢
请您参考如下方法:
在 pyqt4 中为 cbo(组合框)的特定索引行添加颜色:
cbo.model().item(index).setForeground(QtGui.QColor("green"))
cbo.model().item(index).setBackground(QtGui.QColor("red"))
要在 cbo 关闭时显示点击的 cbo 行的文本颜色:
color = cbo.model().item(index).foreground().color().getRgb() #index is index that was clicked
cbo.setStyleSheet("QComboBox:editable{{ color: rgb{} }}".format(color))
如果需要硬编码,那么:
cbo.setStyleSheet("QComboBox:editable{{ color: {} }}".format('red'))
