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. QLabel and QSlider stop updating after a period (using QThread)

QLabel and QSlider stop updating after a period (using QThread)

Scheduled Pinned Locked Moved Solved Qt for Python
3 Posts 3 Posters 991 Views
  • 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.
  • W Offline
    W Offline
    Willow
    wrote on last edited by
    #1

    I am using a thread to setpixmap on a label, and also setValue to change the location of a slider.

        def set_slider(self, currentFrame, lastFrame):
            print(f"Setting slider to: {currentFrame}")
            self.slider.setRange(0,lastFrame)
            self.slider.setValue(currentFrame)
    

    The code above is being called correctly every update loop in the thread and the print outs are ticking up as I would expect.

    However after a period it pauses. I checked the values and everything is still updating and the function is being called correctly, however none of the changes are rendered.

    It feels almost as though the UI is going into sleep mode (I am on a Mac), and I need to wake it up (but selecting the window does nothing, only clicking some kind of button "restarts" the video).

    If I click a test button that does absolutely nothing at all (not hooked up to any function), the UI will begin rendering again.

    I tried calling QApplication.processEvents() after updating the slider but it didn't help.

    jsulmJ 1 Reply Last reply
    0
    • W Willow

      I am using a thread to setpixmap on a label, and also setValue to change the location of a slider.

          def set_slider(self, currentFrame, lastFrame):
              print(f"Setting slider to: {currentFrame}")
              self.slider.setRange(0,lastFrame)
              self.slider.setValue(currentFrame)
      

      The code above is being called correctly every update loop in the thread and the print outs are ticking up as I would expect.

      However after a period it pauses. I checked the values and everything is still updating and the function is being called correctly, however none of the changes are rendered.

      It feels almost as though the UI is going into sleep mode (I am on a Mac), and I need to wake it up (but selecting the window does nothing, only clicking some kind of button "restarts" the video).

      If I click a test button that does absolutely nothing at all (not hooked up to any function), the UI will begin rendering again.

      I tried calling QApplication.processEvents() after updating the slider but it didn't help.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Willow said in QLabel and QSlider stop updating after a period (using QThread):

      def set_slider(self, currentFrame, lastFrame):
      print(f"Setting slider to: {currentFrame}")
      self.slider.setRange(0,lastFrame)
      self.slider.setValue(currentFrame)

      You execute this in a thread?
      If so - don't!
      You should never change UI from other thread than GUI thread.
      Emit a signal from the thread to update the UI.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      W 1 Reply Last reply
      3
      • jsulmJ jsulm

        @Willow said in QLabel and QSlider stop updating after a period (using QThread):

        def set_slider(self, currentFrame, lastFrame):
        print(f"Setting slider to: {currentFrame}")
        self.slider.setRange(0,lastFrame)
        self.slider.setValue(currentFrame)

        You execute this in a thread?
        If so - don't!
        You should never change UI from other thread than GUI thread.
        Emit a signal from the thread to update the UI.

        W Offline
        W Offline
        Willow
        wrote on last edited by
        #3

        @jsulm said in QLabel and QSlider stop updating after a period (using QThread):

        @Willow said in QLabel and QSlider stop updating after a period (using QThread):

        def set_slider(self, currentFrame, lastFrame):
        print(f"Setting slider to: {currentFrame}")
        self.slider.setRange(0,lastFrame)
        self.slider.setValue(currentFrame)

        You execute this in a thread?
        If so - don't!
        You should never change UI from other thread than GUI thread.
        Emit a signal from the thread to update the UI.

        Thanks for the help, I think this is what caused the issue, I changed it to a signal and now it doesn't freeze up anymore!

        @Denni-0 thanks also for the help, however it seems to be working now. Seems like the issue was caused by manually updating from the thread instead of emitting a signal.

        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