PyQT4 Combobox changes the list of another combobox [closed]

我是研究僧i 提交于 2019-12-13 04:48:25

问题


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.

Do I use a if, else statement to change the option for combobox_2?

ex.

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.

If 1 is selected in Combobox_1, Combobox_2 it will show a,b,c.

If 2 is selected in Combobox_1, Combobox_2 will show d,e,f.

If 3 is selected in Combobox_1, Combobox_2 will show g,h,i.

thanks


回答1:


What you want to do is something like this:

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])


来源:https://stackoverflow.com/questions/13502710/pyqt4-combobox-changes-the-list-of-another-combobox

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