0

I use this code for show splash screen before main window is running:

class SplashScreen(QtWidgets.QSplashScreen):
    def __init__(self, parent=None):
        QtWidgets.QSplashScreen.__init__(self, parent)
        self.ui = Ui_splash_screen()
        self.ui.setupUi(self)

    def progress(self):
        for i in range(100):
            time.sleep(0.02)
            self.ui.progressBar.setValue(i)

and its work great wihout threads. But when i use QWidget instead QSplashScreen, my GUI is freeze.

I solved this problem with QApplication.processEvents():

class SplashScreen(QtWidgets.QWidget):
    def __init__(self, parent=None):
        QtWidgets.QWidget.__init__(self, parent)
        self.ui = Ui_splash_screen()
        self.ui.setupUi(self)

    def progress(self):
        for i in range(100):
            time.sleep(0.02)
            QtWidgets.QApplication.processEvents()
            self.ui.progressBar.setValue(i)

But i cannot understand, why its happened? What a differrence between QSplashScreen and QWidget?

  • You should ***not*** use blocking functions like `time.sleep()`. If you want to wait for a long operation to complete, use signals. – musicamante Mar 24 '22 at 12:55

0 Answers0