PyQT4组合框更改另一个组合框的列表 [英] PyQT4 Combobox changes the list of another combobox
问题描述
我刚刚开始使用pyqt4,并且一直坚持如何从另一个组合框更改组合框列表。有某种示例显示了如何使用此方法。
I just started using pyqt4 and am stuck on how to change a combobox list from another combobox. Is there a example of sometype that shows how to work this method.
是否使用if,else语句更改combobox_2的选项?
Do I use a if, else statement to change the option for combobox_2?
ex。
Combobox_1具有1,2,3的列表。 Combobox_2的列表为a,b,c或d,e,f或g,h,i。
Combobox_1 has a list of 1,2,3. Combobox_2 has a list of a,b,c or d,e,f or g,h,i.
如果在Combobox_1中选择了1,则Combobox_2会显示一个,b,c。
If 1 is selected in Combobox_1, Combobox_2 it will show a,b,c.
如果在Combobox_1中选择了2,则Combobox_2将显示d,e,f。
If 2 is selected in Combobox_1, Combobox_2 will show d,e,f.
如果在Combobox_1中选择了3,则Combobox_2将显示g,h,i。
If 3 is selected in Combobox_1, Combobox_2 will show g,h,i.
谢谢
推荐答案
您想要做的就是这样:
def __init__(self):
...
self.items = {'1':['a','b','c'],'2':['d','e','f'],'3':['g','h','i']}
self.Combobox_1.activated[str].connect(self.on_combo_activated)
...
...
def on_combo_activated(self, text):
self.Combobox_2.clear()
self.Combobox_2.addItems(self.items[text])
这篇关于PyQT4组合框更改另一个组合框的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!