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