Setting slider tracking and SliderRelease signal not working
Describe the bug I love the widgets! I've been waiting for someone to properly make these for ages, much better than my own homebrew attempts.
On to the issue(s):
- I have a QLabeledRangeSlider with two handles.
- I expect to be able to access the sliderReleased() signal, however it does not appear to work.
- In its I place I can use valueChanged() - but, because tracking is on by default, it updates continuously as I move a slider.
- I have attempted to turn tracking off but that seems to have no effect: ".setTracking(False)".
- I want to use these signals to get the final resting values of the slider when the mouse releases a handle.
MWE
from PyQt5 import QtCore,QtWidgets
from superqt import QLabeledRangeSlider
import sys
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle('MyWindow')
self.slider = QLabeledRangeSlider(QtCore.Qt.Horizontal)
self.slider.setTracking(False)
self.slider.valueChanged.connect(self.valueChangedCallback)
self.slider.sliderReleased.connect(self.sliderReleasedCallback)
self.setCentralWidget(self.slider)
def valueChangedCallback(self, value):
print(f"valueChangedCallback: {value}")
def sliderReleasedCallback(self, value):
print(f"sliderReleasedCallback: {value}")
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
app.installEventFilter(window)
sys.exit(app.exec_())
Desktop (please complete the following information):
- macOS 10.15.7
- PyQt5=5.15.4
- Python 3.8.13
thanks for the clear example! will try to figure it out. I was able to reproduce, and then get it working on pyqt5 pretty easily by changing a few lines, but the signal-overriding behavior is unfortunately not entirely consistent between different qt backends and versions, so need to dig a bit to come up with a pattern that works consistently.
Hi, I have the same issue. I subclass the QLabelsRangeSlider and I want a mousepress event to send selected handle idx signal.
I tested with the hover event by overloading the event() method, it works only with self.setAttribute(Qt.WidgetAttribute.WA_Hover) in my __init__ constructor.
So I wonder if the signal was blocked and not propagate to the children.
FOUND! Use QLabeledRangeSlider._slider.sliderReleased.connect(yourSlot)
Yea, but don’t use that private access. The slider proxy class is supposed to be forwarding these signals, the bug here is to figure out why it’s not working for sliderReleased
@tlambert03 : OK. Is subclassing QAbstractSlider the problem? Because all "labeled" version use it and have this issue. This issue doesn't exist in the "no labeled" version.
yeah, this is what I meant above by
the signal-overriding behavior is unfortunately not entirely consistent between different qt backends and versions, so need to dig a bit to come up with a pattern that works consistently.
Because there is compiled C code, and different wrappers around that (pyqt vs pyside) overriding signal connections can be a little finicky. that's the underlying core problem here. But I definitely appreciate you taking a look!!
@tlambert03 Hi Talley,
I’m trying QLabeledDoubleRangeSlider in my project, and it’s precisely what I needed. However, I encountered an issue. In my use case, I wanted to utilize the valueChanged signal while setting setTracking(False). Unfortunately, it appears that setTracking(False) doesn’t have the desired effect, as mentioned by @stylekilla.
Given that your last comment dates back over a year, I understand that you might not have the bandwidth to address this issue. Nonetheless, I appreciate your work on this component!
What qt backend and version are you using?
I'm using PySide 6.4.3 for now.
Think I got it fixed in #237. Very sorry for the extremely long delay here everyone. will be in v0.6.3 shortly
Great! Thank you very much.