Getting all items of QComboBox - PyQt4 (Python) Getting all items of QComboBox - PyQt4 (Python) python python

Getting all items of QComboBox - PyQt4 (Python)


As far as I can tell, you can just reference an item using .itemText():

AllItems = [QComboBoxName.itemText(i) for i in range(QComboBoxName.count())]


Building on the accepted answer, you can actually give you combobox a method callable using combo_box.allItems(), by doing this:

    setattr(combo_box, "allItems", lambda: [combo_box.itemText(i) for i in range(self.ui.combo_box.count())])    print(combo_box.allItems()) # Works just fine!

I believe it has to be done in the scope where combo_box was born, otherwise setattr fails.Tested in PyQt5 and Python 3.7.