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. loading screen using a gif image
Forum Updated to NodeBB v4.3 + New Features

loading screen using a gif image

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 3 Posters 600 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.
  • L Offline
    L Offline
    LT-K101
    wrote on last edited by
    #1

    Hi
    I'm trying to show a gif loading image when the user switches between two pages but it seems unsuccessful and causes the app to exit. Below is the code I tried, please I need assistance. Thanks in advance.

    
    self.ui.leftMenuSerch_btn.clicked.connect(self.leftMenu_search_button)
    
     def leftMenu_search_button(self):
         self.loadingScreen()
         self.show()
         self.ui.stackedWidget.setCurrentWidget(self.ui.search_page)
    
    
    def loadingScreen(self):
        self.setFixedSize(150,150)
        self.setWindowFlags(Qt.WindowsStayOnTopHint| Qt.CustomizeWindowHint)
    
        self.label_animation = QLabel(self)
        self.movie = QMovie('file_loading_gif2')
        self.label_animation.setMovie(self.movie)
    
        timer = QTimer(self)
        self.startAnimation()
        timer.singleShot(3000,self.stopAnimation)
        self.show()
    
    
    def startAnimation(self):
        self.movie.start()
    
    
    def stopAnimation(self):
        self.movie.stop()
        self.close()
    
    
    
    JonBJ 1 Reply Last reply
    0
    • L LT-K101

      Hi
      I'm trying to show a gif loading image when the user switches between two pages but it seems unsuccessful and causes the app to exit. Below is the code I tried, please I need assistance. Thanks in advance.

      
      self.ui.leftMenuSerch_btn.clicked.connect(self.leftMenu_search_button)
      
       def leftMenu_search_button(self):
           self.loadingScreen()
           self.show()
           self.ui.stackedWidget.setCurrentWidget(self.ui.search_page)
      
      
      def loadingScreen(self):
          self.setFixedSize(150,150)
          self.setWindowFlags(Qt.WindowsStayOnTopHint| Qt.CustomizeWindowHint)
      
          self.label_animation = QLabel(self)
          self.movie = QMovie('file_loading_gif2')
          self.label_animation.setMovie(self.movie)
      
          timer = QTimer(self)
          self.startAnimation()
          timer.singleShot(3000,self.stopAnimation)
          self.show()
      
      
      def startAnimation(self):
          self.movie.start()
      
      
      def stopAnimation(self):
          self.movie.stop()
          self.close()
      
      
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @LT-K101 said in loading screen using a gif image:

      causes the app to exit.

      Maybe self.close() in stopAnimation() does that? Depends what self is and what top-level windows/widgets are currently open. You can also step through your own code in a Python debugger.

      You should also put error checking into your code, e.g. how do you/we know whether QMovie('file_loading_gif2') even finds the file?

      In terms of your own code, the following:

      def loadingScreen(self)::
          ...
          timer = QTimer(self)
          self.startAnimation()
          timer.singleShot(3000,self.stopAnimation)
          self.show()
      

      looks likely not to achieve anything, since timer is just a local variable and goes out of scope at the end of the function, thereby destroying the timer in Python. Even though you specified QTimer(self), so far as I know, you might verify.

      SGaistS 1 Reply Last reply
      1
      • JonBJ JonB

        @LT-K101 said in loading screen using a gif image:

        causes the app to exit.

        Maybe self.close() in stopAnimation() does that? Depends what self is and what top-level windows/widgets are currently open. You can also step through your own code in a Python debugger.

        You should also put error checking into your code, e.g. how do you/we know whether QMovie('file_loading_gif2') even finds the file?

        In terms of your own code, the following:

        def loadingScreen(self)::
            ...
            timer = QTimer(self)
            self.startAnimation()
            timer.singleShot(3000,self.stopAnimation)
            self.show()
        

        looks likely not to achieve anything, since timer is just a local variable and goes out of scope at the end of the function, thereby destroying the timer in Python. Even though you specified QTimer(self), so far as I know, you might verify.

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

        @JonB singleShot is a static method so it should not be influenced by the fact that the timer variable is local but it's not used in the correct way.

        @LT-K101 out of curiosity, why do you want to make your users wait when switching between two widgets ?

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

        JonBJ 1 Reply Last reply
        0
        • SGaistS SGaist

          @JonB singleShot is a static method so it should not be influenced by the fact that the timer variable is local but it's not used in the correct way.

          @LT-K101 out of curiosity, why do you want to make your users wait when switching between two widgets ?

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @SGaist said in loading screen using a gif image:

          @JonB singleShot is a static method so it should not be influenced by the fact that the timer variable is local but it's not used in the correct way.

          Damn, you're right, and this has come up before, and I forgot again. I wish neither Python nor C++ allowed calling statics from an instance, C# never allowed that!

          SGaistS 1 Reply Last reply
          0
          • JonBJ JonB

            @SGaist said in loading screen using a gif image:

            @JonB singleShot is a static method so it should not be influenced by the fact that the timer variable is local but it's not used in the correct way.

            Damn, you're right, and this has come up before, and I forgot again. I wish neither Python nor C++ allowed calling statics from an instance, C# never allowed that!

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

            @JonB said in loading screen using a gif image:

            @SGaist said in loading screen using a gif image:

            @JonB singleShot is a static method so it should not be influenced by the fact that the timer variable is local but it's not used in the correct way.

            Damn, you're right, and this has come up before, and I forgot again. I wish neither Python nor C++ allowed calling statics from an instance, C# never allowed that!

            C# by iso approval time is not even allowed to drink yet. C++ and Python have at least a decade more behind them ;-)

            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