0

除了退出页面之外,我想让我的 QWizard 上的完成按钮做其他事情。我需要将它连接到调用另一个窗口的函数。换句话说,我需要查看 Qwizard 页面的 Finish Button 并将其添加功能。有谁知道如何做到这一点。谢谢

4

4 回答 4

3

它与您在 PyQt 中已经习惯的做法基本相同。区别在于如何找到完成按钮实体。这是一个工作示例:

import sys
from PyQt5 import QtWidgets, QtCore, QtGui

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

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

class MyWizard(QtWidgets.QWizard):
    def __init__(self, parent=None):
        super(MyWizard, self).__init__(parent)

        self.introPage = IntroPage()
        self.lastPage = LastPage()
        self.setPage(0, self.introPage)
        self.setPage(1, self.lastPage)

        # This is the code you need
        self.button(QtWidgets.QWizard.FinishButton).clicked.connect(self._doSomething)

    def _doSomething(self):
        msgBox = QtWidgets.QMessageBox()
        msgBox.setText("Yep, its connected.")
        msgBox.exec()

if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    main = MyWizard()
    main.show()
    sys.exit(app.exec_())

注意我是如何使用这个命令的:self.button(QtWidgets.QWizard.FinishButton)专门指向完成按钮。剩下的就是建立你自己的方法来做你需要的任何事情。在我的示例中,我连接def _doSomething(self)并启动了一个非常简单的 QMessageBox。

于 2017-09-12T14:11:17.927 回答
1

https://forum.qt.io/topic/44065/how-to-catch-finish-button-pressed-signal-in-qwizard/6

我想这里是回答如何捕捉完成按钮按下事件。我从未使用过 pyqt5,但我认为信号和插槽与 c++ 中的相同。

于 2017-09-12T11:39:34.890 回答
0

当你按下你的 QPushbutton 你有 QWizard 对象?

如果是:

使用信号和插槽!

我不知道它在 Python 中的样子,但 c++ 是这样的:

连接(my_button,SIGNAL(点击(),your_qwizard_object,SLOT(your_qwizard_slot()));

https://wiki.qt.io/Signals_and_Slots_in_PySide

于 2017-09-12T11:02:21.340 回答
0
void MainWindow::on_btnCreateWizard_clicked() { 
    MyWizardForm* dlg = new MyWizardForm(this); 
    connect(dlg, SIGNAL(_finished()), this, SLOT(slot_show_me()));
    this->hide();
    dlg.exec(); 
} 

void MainWindow::slot_show_me() { 
    this->show();
} 

void MyWizardForm::on_btnClose_Clicked() { 
    emit _finished();
    this->reject();
}
于 2017-09-12T11:14:11.823 回答