質問

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!

役に立ちましたか?

解決

Use QComboBox.findText:

    index = myComboBox.findText('item02')
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top