Correct way to show a QSplashScreen

94 Views Asked by At

I am having problems displaying a splashscreen to have user wait to complete startup.

Relevant code (lifted from Qt docs) is as follows:

from PyQt6 import uic, QtWidgets, QtCore, QtGui

class MainWindow(QtWidgets.QMainWindow):
    def __init__(self, *args, **kwargs):
        ... some very long initialization...


def main():
    app = QtWidgets.QApplication(sys.argv)
    pixmap = QtGui.QPixmap('resources/dark-arisen.jpg')
    splash = QtWidgets.QSplashScreen(pixmap)
    splash.show()
    app.processEvents()
    mw = MainWindow()
    mw.show()
    splash.finish(mw)
    sys.exit(app.exec())


if __name__ == "__main__":
    main()

MainWindow.__init__() takes several seconds to complete because it loads and parses a not-so-small XML file.

Apparently something is wrong with initial app.processEvents() because net effect is I see nothing until the initialization is complete, then splash screen flashes very briefly, immediately followed by the main GUI display.

I am working under Linux Debian/Cinnamon, if relevant.

What am I missing?

0

There are 0 best solutions below