Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Is it possible to add MPEG as a splash screen (start up screen)?
Forum Updated to NodeBB v4.3 + New Features

Is it possible to add MPEG as a splash screen (start up screen)?

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 3 Posters 983 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Pythonic person
    wrote on last edited by
    #1

    Hello, I would like to have some animation on the startup window (which will end till the GUIs get ready) instead of a typical image.

    And since the animation is hard to implement with pyqt5( I don't have experience), I would like to use a MPEG format.

    I would appreciate any tutorials that can help me in implementation as well.

    Gojir4G 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You should take a look at the QSplashScreen implementation.

      You would need to add the QtMultimedia module to your application which might be a bit overkill for just the splash screen.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply
      1
      • SGaistS SGaist

        Hi,

        You should take a look at the QSplashScreen implementation.

        You would need to add the QtMultimedia module to your application which might be a bit overkill for just the splash screen.

        P Offline
        P Offline
        Pythonic person
        wrote on last edited by
        #3

        @SGaist Thanks for your answer, Yes, you're right, I noticed that using a Video is not recommended.
        i have many options, I wish that you can help me with them by telling me which is better:

        1. Using MPEG and load it by using QtMultimedia -------------- [Canceled)
        2. is it the same with GIF if I loaded it by using QLabel -> setMovie(QMovie)
        3. Or displaying PNG sequences
        4. or draw it with pyqt5 (but I don't think I can do so)
        5. or stay away from using animation in the splash screen and display a normal image.
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          What kind of animation do you have in mind ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • P Pythonic person

            Hello, I would like to have some animation on the startup window (which will end till the GUIs get ready) instead of a typical image.

            And since the animation is hard to implement with pyqt5( I don't have experience), I would like to use a MPEG format.

            I would appreciate any tutorials that can help me in implementation as well.

            Gojir4G Offline
            Gojir4G Offline
            Gojir4
            wrote on last edited by
            #5

            Hi @Pythonic-person,

            Using QMultimedia can work, but need that QApplication.processEvents() is called permantently from the GUI thread for the video to be displayed correctly, so this is a little bit counter productive as the goal is to show the splashcreen during the loading process. But you can imagine loading everything in a separated thread or manage to call processEvents frequently for that.

            Anyway here is some basic example of a "proof of concept" I did for showing a video in a splashscreen. It is done with PySide6 but except the imports, the code should be quite the same. Hopefully it can help

            from typing import Optional
            from PySide6.QtMultimedia import QMediaPlayer
            from PySide6.QtMultimediaWidgets import QVideoWidget
            from PySide6.QtWidgets import QWidget, QBoxLayout, QSplashScreen, QMainWindow, QLabel
            from PySide6.QtGui import QScreen
            from PySide6.QtCore import Qt, QUrl, QElapsedTimer
            
            class VideoPlayerWidget(QWidget):
                '''Widget for playing videos'''
            
                def __init__(self, path: str,
                            parent: Optional[QWidget] = None) -> None:
                    super().__init__(parent)
                    self.path = path
                    self.__initui__()
            
                def __initui__(self):
                    self.setWindowFlags(Qt.FramelessWindowHint | Qt.WA_TranslucentBackground)
                    self._player = QMediaPlayer()
                    self._player.setSource(QUrl(self.path))
            
                    self._videoWidget = QVideoWidget()
                    self._player.setVideoOutput(self._videoWidget)
            
                    self._player.play()
                    self._player.setLoops(QMediaPlayer.Infinite)
            
                    l = QBoxLayout(QBoxLayout.TopToBottom)
                    l.setContentsMargins(0,0,0,0)
                    l.addWidget(self._videoWidget)
                    self.setLayout(l)
            
            
            class VideoSplash(QSplashScreen):
                ''' Splash screen playing video'''
                def __init__(self, path: str, screen:Optional[QScreen]=None, parent: Optional[QWidget] = None) -> None:
                    super().__init__(screen=screen, parent=parent)
                    self.path = path
                    self.__initui__()
            
                def __initui__(self):
                    ''''''
                    l = QBoxLayout(QBoxLayout.TopToBottom)
                    l.addWidget(VideoPlayerWidget(path=self.path))
                    l.setContentsMargins(0,0,0,0)
                    self.setLayout(l)
                    self.resize(1920/2, 1080/2)
            
            
            class MyWindow(QMainWindow):
                ''''''
                def __init__(self, parent: Optional[QWidget] = None,
                            flags: Qt.WindowFlags = Qt.WindowFlags()) -> None:
                    super().__init__(parent, flags)
            
                    content = QLabel('Main Window')
                    f = content.font()
                    f.setPointSize(20)
                    f.setBold(True)
                    content.setFont(f)
                    self.setCentralWidget(content)
                    self.wait()
            
                def wait(self, timeout=3000) -> None:
                    ''' Sleep few seconds for faking heavy loading process '''
                    elapsed = QElapsedTimer()
                    elapsed.start()
                    while(elapsed.elapsed() < timeout):
                        QApplication.processEvents()
            
            if __name__ == "__main__":
                from PySide6.QtWidgets import QApplication
                import sys
                a = QApplication(sys.argv)
                path = "C:/path/to/my/video.mp4"
            
                s = VideoSplash(path=path)
                screen:QScreen = QApplication.screens()[0]
                # move at center
                s.move((screen.size().width() - s.size().width()) / 2, (screen.size().height() - s.size().height()) / 2)
                s.show()
                QApplication.processEvents()
            
                w = MyWindow()
                s.finish(w)
                w.show()
            
                a.exec()
            
            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved