Search code examples
pyqt5splash-screenpython-3.8

Python PyQt5 movie splash screen


I wanted to have a .mp4 or .gif file as a splashscreen. I'm using Python 3.8 and PyQt5. I tried to do it myself but didn't succeed. Does any1 know how?

I tried this:

import sys, time
from PyQt5.QtGui import *
from PyQt5.QtWidgets import QSplashScreen, QApplication, QWidget


class MovieSplashScreen(QSplashScreen):

    def __init__(self, movie, parent=None):
        movie.jumpToFrame(0)
        pixmap = QPixmap(movie.frameRect().size())

        QSplashScreen.__init__(self, pixmap)
        self.movie = movie
        self.movie.frameChanged.connect(self.repaint)
    def paintEvent(self, event):
        painter = QPainter(self)
        pixmap = self.movie.currentPixmap()
        self.setMask(pixmap.mask())
        painter.drawPixmap(0, 0, pixmap)

if __name__ == "__main__":

    app = QApplication(sys.argv)
    movie = QMovie("splash.gif")
    splash = MovieSplashScreen(movie)
    splash.show()

    start = time.time()

    while movie.state() == QMovie.Running and time.time() < start + 10:
        app.processEvents()

    window = QWidget()
    window.show()
    splash.finish(window)

    sys.exit(app.exec_())

Solution

  • You need to start the QMovie:

    # ...
    splash.show()
    splash.movie.start()
    # ...