Getting all items of QComboBox - PyQt4 (Python)

て烟熏妆下的殇ゞ 提交于 2020-06-25 07:28:19

问题


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


回答1:


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

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


来源:https://stackoverflow.com/questions/7479915/getting-all-items-of-qcombobox-pyqt4-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!