在 QWizard 上按完成时调用功能 [英] Call function when press finish on QWizard

查看:125
本文介绍了在 QWizard 上按完成时调用功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在按下 QWizard 上的完成按钮后触发功能?我正在使用 PyQT5.到目前为止,我只在按下取消"或完成"按钮时才设法这样做,但是我只需要在按下完成"按钮时触发

How can I trigger a function after pressing the finish button on a QWizard? I am using PyQT5. Up until now I have only managed to do so when either Cancel or Finish buttons are pressed, however I only need a trigger when the Finish button is pressed

class ImportWizard(QtWidgets.QWizard):
def __init__(self, parent=None):
    super(ImportWizard, self).__init__(parent)
    self.addPage(Page1(self))
    self.addPage(Page2(self))
    self.setWindowTitle("Import Wizard")

    # Trigger close event when pressing Finish button
    app.aboutToQuit.connect(self.onFinish)

def onFinish(self):
    print("Wizard closes")

推荐答案

我刚刚找到它.解决方案是交换 app.aboutToQuit.connect(self.onFinish)self.button(QtWidgets.QWizard.FinishButton).clicked.connect(self.onFinish)

I just found it. The solution was to swap the app.aboutToQuit.connect(self.onFinish) line with self.button(QtWidgets.QWizard.FinishButton).clicked.connect(self.onFinish)

这篇关于在 QWizard 上按完成时调用功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆