Search code examples
pythonqtpysideqstackedwidget

Two function one after the other when clicked pushbutton - Pyside


I have a little problem with py pyside script. I make a setup wizard and I want to change my current widget in my stackedwidget then make the all installation of librairies etc...

I've tried two solutions:

The first is this one:

self.pushButton.clicked.connect(lambda: changepage(self, MainWindow))
self.pushButton.clicked.connect(lambda: makeinstall(self, MainWindow))

and it doesn't work, the window don't change and my installation is launch.

The second is:

def changepage(self, MainWindow):
     self.stackedWidget.setCurrentIndex(4)
     makeinstall(self, MainWindow)

and it doesn't work too. In the two solutions, the page is changed after the installation (after the end of the function I think).

Did someone have a solution to run two function, one after the other in pyside?

Regards,


Solution

  • The slot connected to the signal is called synchronously, so the GUI will not be updated until it returns. There are lots of different ways to solve this, but you can try forcing an update like this:

    def changepage(self, MainWindow):
        self.stackedWidget.setCurrentIndex(4)
        QtGui.qApp.processEvents()
    

    Or if that doesn't work, try using a single-shot timer to run the installer:

        QtCore.QTimer.singleShot(0, lambda: makeinstall(self, MainWindow))