6

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)));
evilSquirrel
  • 61
  • 1
  • 2

2 Answers2

4

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.

shubh
  • 131
  • 3
  • Thanks a lot, this was a good hint, but sadly I still could not fix the problem. But it helped to understand the problem a bit better. I am using a QProgressDialog because the operation of changing the sliders value results in a time consuming calculation. As a result the slider seems to work better, because after increasing the value by pageStep size, it also seems to get the signal to set it to the value I clicked on. – evilSquirrel Sep 17 '12 at 08:21
3

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

Community
  • 1
  • 1
Ben
  • 1,519
  • 23
  • 39