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
If you want the text value of a QString object you can use the __str__ property, like this: >>> a = QtCore.
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.
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.
As far as I can tell, you can just reference an item using .itemText()
:
AllItems = [QComboBoxName.itemText(i) for i in range(QComboBoxName.count())]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With