superqt icon indicating copy to clipboard operation
superqt copied to clipboard

Setting slider tracking and SliderRelease signal not working

Open stylekilla opened this issue 3 years ago • 6 comments

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

stylekilla avatar Apr 24 '22 05:04 stylekilla

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.

tlambert03 avatar Apr 24 '22 13:04 tlambert03

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.

looninho avatar Jun 15 '22 10:06 looninho

FOUND! Use QLabeledRangeSlider._slider.sliderReleased.connect(yourSlot)

looninho avatar Jun 16 '22 12:06 looninho

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 avatar Jun 16 '22 12:06 tlambert03

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

looninho avatar Jun 16 '22 13:06 looninho

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 avatar Jun 16 '22 13:06 tlambert03

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

jiban avatar Mar 27 '24 05:03 jiban

What qt backend and version are you using?

tlambert03 avatar Mar 27 '24 09:03 tlambert03

I'm using PySide 6.4.3 for now.

jiban avatar Mar 27 '24 09:03 jiban

Think I got it fixed in #237. Very sorry for the extremely long delay here everyone. will be in v0.6.3 shortly

tlambert03 avatar Mar 27 '24 21:03 tlambert03

Great! Thank you very much.

jiban avatar Mar 28 '24 02:03 jiban