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. QMovie displays GIF with delay.
Qt 6.11 is out! See what's new in the release blog

QMovie displays GIF with delay.

Scheduled Pinned Locked Moved Unsolved Qt for Python
8 Posts 2 Posters 1.7k Views 1 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.
  • B Offline
    B Offline
    BigZet
    wrote on last edited by BigZet
    #1

    Hi :)
    I try to create Loader screen with GIF showing that data is processed.
    I use PyQT5 and widgets.
    I created QLabel and I set movie on it.
    I works fine when I test it as standalone app.
    But when I use it in my target app dialogs shows up, but animation is loaded after logic processing data is finished. Any other actions made on gui (showing progress bar etc) are not working as well.
    I've read that it is caused by fact that GUI thread is to busy. Is there anything I can do about this?
    Can I start this widget in separate thread?
    I tried to call processEvents() before showing dialog but it does not help.
    Best regards!

    UPDATE: I put processEvents() in few more places during logic processing and it works fine, however I'm not sure if this is good practice to do so manually. Is there better solution?

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

      Hi,

      Looks like your a blocking the event loop with your data processing.

      Without seeing your code is hard to tell but needing to sprinkle calls to processEvent everywhere is sign of a big design issue.

      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
      • B Offline
        B Offline
        BigZet
        wrote on last edited by
        #3

        Thank you for your response.
        It's quite big application so I can't paste whole code, but I will try to give the essence of it:
        main.py:

        if __name__ == "__main__":
            oldHook = sys.excepthook
            sys.excepthook = catchExceptions
            app = QApplication([])
            engine = ToolEngine()  #inherits from QObject (emits signals and performs main logic, but not as slots, functions are called from another functions created in MainWindow.py
            window = MainWindow(engine)
            window.show()
            # customizing exceptions hook due to fact that some exceptions were not shown in interactive console in PyCharm
            log.debug("App exec")
            retCode = app.exec_()
            sys.exit(retCode)
        

        and file with MainWindow.py:

        class MainWindow(QMainWindow):
            def __init__(self, engine, *args):
                #....
                uic.loadUi(guiPath, self) # quite complex ui file with table, grids etc
                self.backend = engine # can this method of passing backend be a problem? 
                #...
                self.buttonSave.clicked.connect(self.backend.saveChanges)   #function not slot
                self.someButton.clicked.connect(self.someFunction1)  #function not slot
                self.backend.saveStarted.connect(self.showLoadingScreen) #shows QWidget with Label containing QMovie
        
            def someFunction1(self):
                self.backend.doSomeCalculations()
        

        Can you see anything wrong basing on those snippets or thats not clear/enough?

        SGaistS 1 Reply Last reply
        0
        • B BigZet

          Thank you for your response.
          It's quite big application so I can't paste whole code, but I will try to give the essence of it:
          main.py:

          if __name__ == "__main__":
              oldHook = sys.excepthook
              sys.excepthook = catchExceptions
              app = QApplication([])
              engine = ToolEngine()  #inherits from QObject (emits signals and performs main logic, but not as slots, functions are called from another functions created in MainWindow.py
              window = MainWindow(engine)
              window.show()
              # customizing exceptions hook due to fact that some exceptions were not shown in interactive console in PyCharm
              log.debug("App exec")
              retCode = app.exec_()
              sys.exit(retCode)
          

          and file with MainWindow.py:

          class MainWindow(QMainWindow):
              def __init__(self, engine, *args):
                  #....
                  uic.loadUi(guiPath, self) # quite complex ui file with table, grids etc
                  self.backend = engine # can this method of passing backend be a problem? 
                  #...
                  self.buttonSave.clicked.connect(self.backend.saveChanges)   #function not slot
                  self.someButton.clicked.connect(self.someFunction1)  #function not slot
                  self.backend.saveStarted.connect(self.showLoadingScreen) #shows QWidget with Label containing QMovie
          
              def someFunction1(self):
                  self.backend.doSomeCalculations()
          

          Can you see anything wrong basing on those snippets or thats not clear/enough?

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @BigZet said in QMovie displays GIF with delay.:

          self.backend = engine # can this method of passing backend be a problem?

          No, it's just an assignment.

          @BigZet said in QMovie displays GIF with delay.:

          self.backend.saveStarted.connect(self.showLoadingScreen) #shows QWidget with Label containing QMovie

          What I suspect is that the method which emit saveStarted then does a lot of long stuff thus blocking the event loop hence the movie not playing as you'd expect.

          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
          • B Offline
            B Offline
            BigZet
            wrote on last edited by
            #5

            So I should do this on separate thread to not block GUI thread?

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

              Not knowing what you do in it I can't really comment on whether threading or reworking your code is the best solution.

              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
              • B Offline
                B Offline
                BigZet
                wrote on last edited by
                #7

                Ok, I understand. Thank you for your help!
                I had so many problems making Python work with widgets that I will probably rewrite it to QML.

                Thanks!

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

                  That won't change anything if you are blocking the event loop be it with widgets or QtQuick, you'll have similar issue.

                  I highly recommend to fix the blocking parts so you can more freely change the GUI stack if you really want to.

                  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
                  1

                  • Login

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