Question

Created myComboBox with:

myComboBox = QtGui.QComboBox()

Populated it with three items:

myItemsList = ['item01', 'item02', 'item03']

for item in myItemsList:
    myComboBox.addItem(item)

Now I want to set a comboBox to a second item knowing only string value of the item: 'item02'.

Let's assume I can't index myItemsList to find out what indexed position of an item with a value 'item02'.

I want to set a myComboBox without using an item index number but its string value. Thanks in advance!

Was it helpful?

Solution

Use QComboBox.findText:

    index = myComboBox.findText('item02')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top