pyqt:how 在单击 QwizardPage 的 NextButton 时发出信号

pyqt:how to emit a signal when NextButton of a QwizardPage was clicked

我创建了一个包含多个页面的 QWizard 对象,我试图在单击特定页面的 NextButton 时打开一个文件。起初,我尝试了QWizard.NextButton.clicked.connect(),结果是: "AttributeError: 'WizardButton' 对象没有属性 'clicked''。

之后,我在Qt Assistant中搜索"WizardButton",没有得到任何有用的信号发出,是否可以像QPushButton.clicked.connect()那样实现?

具体页面如下:

class AccountPage(QWizardPage):

    def __init__(self, parent=None):
        super(AccountPage, self).__init__(parent)

        self.setTitle("Account Information")

        NameLabel = QLabel("&Name:")
        NameLineEdit = QLineEdit()
        NameLabel.setBuddy(NameLineEdit)

        EmailLabel = QLabel("&Email Address:")
        EmailLineEdit = QLineEdit()
        EmailLabel.setBuddy(EmailLineEdit)

        PwdLabel = QLabel("&Password:")
        PwdLineEdit = QLineEdit()
        PwdLabel.setBuddy(PwdLineEdit)

        self.registerField('Name*', NameLineEdit)
        self.registerField('EmailAddress*', EmailLineEdit)
        self.registerField('Password*', PwdLineEdit)

        layout = QGridLayout()
        layout.addWidget(NameLabel, 0, 0)
        layout.addWidget(NameLineEdit, 0, 1)
        layout.addWidget(EmailLabel, 1, 0)
        layout.addWidget(EmailLineEdit, 1, 1)
        layout.addWidget(PwdLabel, 2, 0)
        layout.addWidget(PwdLineEdit, 2, 1)

        self.setLayout(layout)

        QWizard.NextButton.clicked.connect(self.setMB)

    def setMB(self):
        try:
            with open('mb.ini', 'w') as actInfo:
                actInfo.write('sj')

        except IOError as err:
            print('mb.ini error:' + str(err))
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *

class Window(QWizard):  
    def __init__(self):
        super(Window, self).__init__()
        self.accoutPage = AccountPage()
        self.secondPage = Page2()
        self.thirdPage = Page3()
        self.addPage(self.accoutPage)
        self.addPage(self.secondPage)
        self.addPage(self.thirdPage)
        self.button(QWizard.NextButton).clicked.connect(self.accoutPage.setMB)


class AccountPage(QWizardPage):
    def __init__(self, parent=None):
        super(AccountPage, self).__init__(parent)

        self.setTitle("Account Information")

        self.NameLabel = QLabel("&Name:")
        self.NameLineEdit = QLineEdit()
        self.NameLabel.setBuddy(self.NameLineEdit)

        self.EmailLabel = QLabel("&Email Address:")
        self.EmailLineEdit = QLineEdit()
        self.EmailLabel.setBuddy(self.EmailLineEdit)

        self.PwdLabel = QLabel("&Password:")
        self.PwdLineEdit = QLineEdit()
        self.PwdLabel.setBuddy(self.PwdLineEdit)

        self.registerField('Name*', self.NameLineEdit)
        self.registerField('EmailAddress*', self.EmailLineEdit)
        self.registerField('Password*', self.PwdLineEdit)


        layout = QGridLayout()
        layout.addWidget(self.NameLabel, 0, 0)
        layout.addWidget(self.NameLineEdit, 0, 1)
        layout.addWidget(self.EmailLabel, 1, 0)
        layout.addWidget(self.EmailLineEdit, 1, 1)
        layout.addWidget(self.PwdLabel, 2, 0)
        layout.addWidget(self.PwdLineEdit, 2, 1)

        self.setLayout(layout)
        self.i = 0 #if you need to call it once

    def setMB(self):
        if self.i == 0: 
            print(self.PwdLineEdit.text(), self.i) 
            try:
                with open('mb.ini', 'w') as actInfo:
                    actInfo.write('sj')

            except IOError as err:
                print('mb.ini error:' + str(err))
            finally:
                self.i += 1


class Page2(QWizardPage):
    def __init__(self):
        super(Page2, self).__init__()

class Page3(QWizardPage):
    def __init__(self):
        super(Page3, self).__init__()

def main():
    app = QApplication(sys.argv)
    app.setStyle('plastique')

    window = Window()
    window.setWizardStyle(1)
    window.show()
    app.exec_()  

if __name__ == "__main__":
    sys.exit(main())