问题描述
我有很多QComboBoxes
,在某个时候,我需要获取特定QComboBox
的每一项以进行迭代.
尽管我只可以列出与QComboBox
中的项目相对应的项目列表,但我还是希望直接从小部件本身获取它们(存在大量的QComboBoxes
,每个项目都有很多项目).
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.
我想到了一些凌乱的方法,但是我不喜欢它们.
(就像通过更改索引并获取项目等遍历QComboBox
一样.)
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
闲置1.8
Windows 7
PyQt4
Python 2.7.1
IDLE 1.8
Windows 7
PyQt4
推荐答案
据我所知,您可以使用.itemText()
引用项目:
As far as I can tell, you can just reference an item using .itemText()
:
AllItems = [QComboBoxName.itemText(i) for i in range(QComboBoxName.count())]
这篇关于获取QComboBox的所有项目-PyQt4(Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!