簡體   English   中英

選擇其他組合框/列表框項時顯示QMessageBox PyQT

[英]display a QMessageBox PyQT when a different combobox /list box item is selected

我有一個組合框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示例。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM