I’m trying to trigger a distinct signal from a QSlider for when it increases or decreases. Unfortunately due to restrictions in the program i’m creating outside of my control I cannot track the value of the slider and just do a comparison.
Is there a way to do this?
If I understand you correctly, you can’t use
valueChanged(int)to decide if the value increased or decreased, since you can’t track the value. However, you need to do this, since QSlider doesn’t have distinct signals for an increased / decreased value.Use this helper class to keep track of the current value. It remaps the signal
valueChanged(int)of the provided target object to the new signalsvalueIncreased(int)andvalueDecreased(int)telling the (absolute) difference.To use it, simply create a new instance of this class and connect to its signals. In the QObject tree, it becomes a child of the target object, so you don’t have to keep the pointer to an instance.