display a QMessageBox PyQT when a different combobox /list box item is selected
Question
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))
Solution
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow