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 577 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 26 Sept 2022, 14:48 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()
    
    
    
    J 1 Reply Last reply 26 Sept 2022, 14:59
    0
    • L LT-K101
      26 Sept 2022, 14:48

      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()
      
      
      
      J Offline
      J Offline
      JonB
      wrote on 26 Sept 2022, 14:59 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.

      S 1 Reply Last reply 26 Sept 2022, 18:10
      1
      • J JonB
        26 Sept 2022, 14:59

        @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.

        S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 26 Sept 2022, 18:10 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

        J 1 Reply Last reply 26 Sept 2022, 18:12
        0
        • S SGaist
          26 Sept 2022, 18:10

          @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 ?

          J Offline
          J Offline
          JonB
          wrote on 26 Sept 2022, 18:12 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!

          S 1 Reply Last reply 26 Sept 2022, 18:15
          0
          • J JonB
            26 Sept 2022, 18:12

            @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!

            S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 26 Sept 2022, 18:15 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

            1/5

            26 Sept 2022, 14:48

            • Login

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