3

I'm using QSlider object in my Qt application and I want to get the position of the slider bar upon moving it. I tried using pos() function, but it always returns QPoint() with the same values of x and y (i suppose it returns position of top left corner of slider):

ui->horizontalSlider->pos();

Then I tried dividing the slider width by 100 and adding that value multiplicated by slider value() to most-left position:

SliderStep = ui->horizontalSlider->width()/100;

(ui->horizontalSlider->value()) * SliderStep + ui->horisontalSlider->geometry().x();

It kind of works for me, but values are not very accurate since SliderStep has to be double and coordinates are integer values. I always noticed that I can get slider values by either using value() or sliderPosition() functions since they always return the same value for me:

qDebug()<<ui->horizontalSlider->sliderPosition();
qDebug()<<ui->horizontalSlider->value();

So my question is, is there a more convinient or "right" way to get coordinates of a slider bar? What's the difference between those two functions? Any help is appreciated.

yacc
  • 2,915
  • 4
  • 19
  • 33
George
  • 578
  • 4
  • 21

0 Answers0