问题
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