1

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

lunarcrusader
  • 13
  • 1
  • 3

1 Answers1

3

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])
BrtH
  • 2,610
  • 16
  • 27
  • great that worked, any tips on if I had three combo boxes instead of two? – lunarcrusader Nov 21 '12 at 23:40
  • You could maybe do something with the [currentIndexChanged](http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qcombobox.html#currentIndexChanged) signal in the second combobox. An other possibility is using a second dict for the items in the third combobox, with all the values of combobox_2 as keys, and then do `self.Combobox_3.addItems(self.items_2[self.Combobox_2.currentText()])`. – BrtH Nov 22 '12 at 17:32