选择其他组合框/列表框项时显示QMessageBox PyQT

2024-04-18 20:35:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个组合框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在以下表单中选择不同的项目时弹出:

^{pr2}$

Tags: and函数fromnewondef格式item
1条回答
网友
1楼 · 发布于 2024-04-18 20:35:36

编写包含此代码的方法或函数,并将其附加到组合框信号^{}

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示例。在

相关问题 更多 >