pythonpython-3.xpyqtpyqt5qwizard

How to put some validation on Qwizard finish button slot and get confirmation before qwizard finishing?


I try to put some validations on user inputs and display a summery of entered information and get confirm from user if all thing is right. I think i need to modify the slot of QWizard FinishButton but i cannot find the main slot.

I try this way but wizard is immediately closed on finish clicking.

self.button(QtWidgets.QWizard.FinishButton).clicked.connect(self.do_something)

def do_something():
    #do something 

Solution

  • If you want to validate after pressing the "Finish" button then you must disconnect the clicked signal from the associated slots (such as the accept() slot), connect it to the new slot and if it is valid to call the accept() function:

        # ...
        finish_button = self.button(QtWidgets.QWizard.FinishButton)
        finish_button.disconnect()
        finish_button.clicked.connect(self.finish_validate)
    
    @QtCore.pyqtSlot()
    def finish_validate(self):
        button = QtWidgets.QMessageBox.question(self, "Validation", "Is valid?")
        if button == QtWidgets.QMessageBox.Yes:
            self.accept()