I am trying to use a QSlider, but if somebody clicks on a position X, where he wants to put the slider to, the slider always sets the value to maximum or minimum at first and then to the value X. So there is an unnecessary step in-betweeen. How can I avoid this step?
I implemented the slider with the help of QTDesigner. The code for the remaining setup is the following:
_ui->horizontalSlider->setRange(1, aMaximalValue);
_ui->horizontalSlider->setValue(theCurrentValue);
connect(_ui->horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(onValueOfSliderChanged(int)));
When using a QSlider, my experience says that when you click at a certain position in the slider which is to right of current position(considering horizontal slider), it will increase slider value by pageStep size. Similarly, if click value is to left of current position, it will decrease slider value by pageStep size. Only when you drag the slider to that place, it will set the value to what you want and not on clicking. Try setting the pageStep size to see if this is the issue.
Yes, just like shubh explained, the pagestep is probably too large. A common issue with QSliders is that they do not jump to the position you have clicked, but move a pagestep in that direction.
A solution to that problem has been described in this question
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With