1

I am trying to show splashscreen before loading the mainwindow but a transparent window is displayed instead of the intended image. The splashscreen is supposed to be displayed after import and instantiation loading of Dashboard, which takes a few seconds, but the image only shows when the splash screen is about to close. Below is my code:

from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt, QThread
from PyQt5.QtGui import QPixmap
from modules.video_opening.map.map import Map
import sys

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    splash_pic = QPixmap('splash.png')

    splash = QtWidgets.QSplashScreen(splash_pic, Qt.WindowStaysOnTopHint)
    splash.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)
    splash.setEnabled(False)
    splash.setMask(splash_pic.mask())
    splash.showMessage("<h6>Loading...</h6>", Qt.AlignBottom | Qt.AlignRight, Qt.black)
    splash.show()
    app.processEvents()

    from modules.dashboard import Dashboard
    dashboard = Dashboard()
    splash.finish(dashboard)
    dashboard.show()

    app.exec_()
Teddy Ondieki
  • 147
  • 1
  • 11

1 Answers1

0

Here's what's working for me at the moment: adding a loop of app.processEvents()

from PyQt5 import QtWidgets
from PyQt5.QtCore import Qt, QThread
from PyQt5.QtGui import QPixmap
from modules.video_opening.map.map import Map
import sys

if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    splash_pic = QPixmap('splash.png')

    splash = QtWidgets.QSplashScreen(splash_pic, Qt.WindowStaysOnTopHint)
    splash.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint)
    splash.setEnabled(False)
    splash.setMask(splash_pic.mask())
    splash.showMessage("<h6>Loading...</h6>", Qt.AlignBottom | Qt.AlignRight, Qt.black)
    splash.show()

    for i in range(10000):
        app.processEvents()

    from modules.dashboard import Dashboard
    dashboard = Dashboard()
    splash.finish(dashboard)
    dashboard.show()

    app.exec_()
Teddy Ondieki
  • 147
  • 1
  • 11