PyQt: QCombobox background text color not reflected in selected state
Hi guys,
The following code works but doesn't do in full what exactly is needed:
Code:
nameList = ('John','Tom','Henry','Michelle','Ashish','Jo-Huang', ...)
colorNameList = ('Michelle','Jennifer','Claudia','JimSung', ...)
callBackObj.NameComboBox.clear()
callBackObj.
NameComboBox.
addItem(QString('Account Names'))model = callBackObj.NameComboBox.model()
for name in nameList:
if name in colorNameList:
item.
setBackground(PyQt4.
QtGui.
QColor('red')) model.appedRow(item)
Now whenever I expand and view the dropdown, the names in colorNameList appear in red background. So far so good. However when I select one of these red-background names they do not show as red-background when left selected.
Any ideas how I can ensure that on selection red items appear red and non-red appears non-red.
Many thanks!
Rahul
Re: PyQt: QCombobox background text color not reflected in selected state
When an entry is selected Qt applies a highlight color on it. You need to alter that as well.
Re: PyQt: QCombobox background text color not reflected in selected state
Hi wysota,
Thanks for your response. However can you advise on how this can be achieve in python. Please refer to the code snippet in my original post above.
Rahul
Re: PyQt: QCombobox background text color not reflected in selected state
Your original snippet deals with a model while the highlight happens in the view through the delegate. Thus you need to either implement a custom delegate or set the highlight color in your view's palette to transparent.
Re: PyQt: QCombobox background text color not reflected in selected state
Hi wysota
Thanks for your response. I am new to PyQt; would it be possible for you to provide a code snippet to do so.
Many Thanks
Rahul
Re: PyQt: QCombobox background text color not reflected in selected state
I am new to PyQt too so we're starting from the same point so you can provide that code snippet yourself as well. You have two hints -- custom delegate and changing the widget's palette.