عرض QMessageBox Pyqt عند تحديد عنصر مختلف Combobox / قائمة مربع
سؤال
لدي مربع التحرير والسرد cbLayer
وظائف do_stuff
النموذج التالي:
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
كيف يمكنني الحصول على QMessageBox
إلى السطح كلما تم تحديد عنصر مختلف في النموذج التالي:
QMessageBox.warning(self, "items: ", do_stuff(cb_selected_item))
المحلول
اكتب طريقة أو وظيفة تحتوي على هذا الرمز وإرفاقه إلى إشارة مربعات التحرير والسرد 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))
لم أحاول ذلك ولكن يجب أن تبدأك. خلاف ذلك إلقاء نظرة على أمثلة PYQT.
لا تنتمي إلى StackOverflow