Merry Christmas guys!
I am new to PyQt4 programming and using Qt Designer for most of UI development. However I have a specific requirement to populate a QComboBox through Python code. More so I want to change text formatting (Bold, Red Background color) for some of the entries.
Essentially the combobox entries should appear as follows:
John
Tom
Henry
Michelle
Ashish
Jo-Huang
....
In terms of code I want to do something like this:
nameList = ('John','Tom','Henry','Michelle','Ashish','Jo-Huang', ...)
colorNameList = ('Michelle','Jennifer','Claudia','JimSung', ...)
callBackObj.NameComboBox.clear()
callBackObj.NameComboBox.addItem(QString('Account Names'))
for name in nameList:
if name in colorNameList:
callBackObj.NameComboBox.addItem(name) #Make this entry bold and red background
else:
callBackObj.NameComboBox.addItem(name)
The following code failed:
nameList = ('John','Tom','Henry','Michelle','Ashish','Jo-Huang', ...)
colorNameList = ('Michelle','Jennifer','Claudia','JimSung', ...)
callBackObj.NameComboBox.clear()
callBackObj.NameComboBox.addItem(QString('Account Names'))
for name in nameList:
item = PyQt4.QtGui.QStandardItem(str(account))
if name in colorNameList:
item.setBackground(PyQt4.QtGui.QColor('red'))
callBackObj.NameComboBox.addItem(item)
Error msg:
TypeError: arguments did not match any overloaded call:
QComboBox.addItem(QString, QVariant userData=QVariant()): argument 1 has unexpected type 'QStandardItem'
QComboBox.addItem(QIcon, QString, QVariant userData=QVariant()): argument 1 has unexpected type 'QStandardItem'
The following code worked :):
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:
item = PyQt4.QtGui.QStandardItem(str(account))
if name in colorNameList:
item.setBackground(PyQt4.QtGui.QColor('red'))
model.appedRow(item)
Many Thanks
Rahul
TypeError: arguments did not match any overloaded call: QComboBox.addItem(QString, QVariant userData=QVariant()): argument 1 has unexpected type 'QStandardItem' QComboBox.addItem(QIcon, QString, QVariant userData=QVariant()): argument 1 has unexpected type 'QStandardItem' – Rahul Dec 25 '14 at 22:14