3

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!

ekhumoro
  • 115,249
  • 20
  • 229
  • 336
alphanumeric
  • 17,967
  • 64
  • 244
  • 392

1 Answers1

5

Use QComboBox.findText:

    index = myComboBox.findText('item02')
ekhumoro
  • 115,249
  • 20
  • 229
  • 336