tags:

views:

442

answers:

1

I have a combo box cbLayer and a function do_stuff of the following form:

def do_stuff(item_selected_from_cbLayer):
    new_list = []
    # do stuff based on item_selected_from_combobox and put the items in new_list
    return new_list

How can I get a QMessageBox to pop up whenever a different item is selected in the following form:

QMessageBox.warning(self, "items: ", do_stuff(cb_selected_item))
+1  A: 

Write a method or function that contains this code and attach it to the combo boxes signal currentIndexChanged:

def __init__(self):
    ...
    QObject.connect(self.cbLayer, SIGNAL("currentIndexChanged(int)"), self.warn)

def warn(index):
    QMessageBox.warning(self, "items: ", do_stuff(cbLayer.itemData(index)) )

def do_stuff(self, item):
    QMessageBox.warning(self, str(item))

I didn't try this but it should get you started. Otherwise have a look at the PyQt examples.

Aaron Digulla
thanks for the code, here's the final result QObject.connect(self.cbLayer, SIGNAL("currentIndexChanged(int)"), self.warn \n def do_stuff(self, item): \n QMessageBox.warning(self, str(item)) Would you please change your code accordingly?
dassouki
Sure. Is it correct, now?
Aaron Digulla