Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QSlider makes unnecessary steps

Tags:

qt

qslider

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)));
like image 480
evilSquirrel Avatar asked Sep 13 '12 15:09

evilSquirrel


2 Answers

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.

like image 199
shubh Avatar answered Nov 11 '22 19:11

shubh


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

like image 3
Ben Avatar answered Nov 11 '22 21:11

Ben