Reputation: 61
I want to have the finish button on my QWizard do something else besides exit the page. I need to connect it to a function that calls another window. In other words, I need to view and add functionality to the Finish Button of the Qwizard page. Does anyone know how to do this. Thanks
Upvotes: 0
Views: 1840
Reputation: 13465
Its mostly the same you are already used to do in PyQt. The differences are in how to find the Finish button entity. Here is a working example:
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_())
Notice how I used this command: self.button(QtWidgets.QWizard.FinishButton)
to specifically point to the finish button. The rest is just build your own method to do whatever you need. In my example I connected to def _doSomething(self)
and launched a very simple QMessageBox.
Upvotes: 4
Reputation: 3093
https://forum.qt.io/topic/44065/how-to-catch-finish-button-pressed-signal-in-qwizard/6
I think here is answer how to catch finish button press event. I have never worked with pyqt5 but I think signal and slot is the same as in c++.
Upvotes: 1
Reputation: 1489
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();
}
Upvotes: 0
Reputation: 1489
When Your Press on your QPushbutton You Have QWizard Object?
if yes:
use SIGNAL and SLOT!
I do not know how it looks like in Python, but c++ like this:
connect(my_button, SIGNAL(clicked(), your_qwizard_object, SLOT(your_qwizard_slot()));
https://wiki.qt.io/Signals_and_Slots_in_PySide
Upvotes: 0