Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting all items of QComboBox - PyQt4 (Python)

I have A LOT of QComboBoxes, and at a certain point, I need to fetch every item of a particular QComboBox to iterate through.
Although I could just have a list of items that correspond to the items in the QComboBox, I'd rather get them straight from the widget itself (there are a huge amount of QComboBoxes with many items each).

Is there any functions / methods that will do this for me?
(Eg:

 QComboBoxName.allItems() 

)
I've looked through the class reference but couldn't find anything relevant.

I've thought of a few messy methods, but I don't like them.
(Like iterating through the QComboBox by changing the index and getting the item, etc).


Python 2.7.1
IDLE 1.8
Windows 7
PyQt4

like image 536
Anti Earth Avatar asked Sep 20 '11 03:09

Anti Earth


People also ask

How do I get text from QComboBox?

If you want the text value of a QString object you can use the __str__ property, like this: >>> a = QtCore.

How do I add items to QComboBox in Python?

A combobox can be created with the QComboBox class. Items are added using the class method addItem, followed by a string parameter. Sometimes its called a listbox, as it shows a list of items a user can select from. If you want a user to choose from a set of items, the listbox is the best option.

How do I create a drop down menu in PYQT?

First, we define the comboBox, then we add a bunch of options, then we move the comboBox (a drop down button). When the combo box has a choice, it will take the string version of the choice, and run self.


1 Answers

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

AllItems = [QComboBoxName.itemText(i) for i in range(QComboBoxName.count())] 
like image 169
Blender Avatar answered Sep 22 '22 07:09

Blender