PDA

View Full Version : Does Qt has a doubleSlider which works with double values?



Hossein
21st October 2015, 11:21
Hello everyone.
I need a slider which accepts steps in double . the current slider in QtCreator works only with integers.
I searched a bit and I couldnt find any double based slider in the documents so far.
I found this as well :


class DoubleSlider : public QSlider {
Q_OBJECT

public:
DoubleSlider(QWidget *parent = 0) : QSlider(parent) {
connect(this, SIGNAL(valueChanged(int)),
this, SLOT(notifyValueChanged(int)));
}

signals:
void doubleValueChanged(double value);

public slots:
void notifyValueChanged(int value) {
double doubleValue = value / 10.0;
emit doubleValueChanged(doubleValue);
}
};

But this approach has several shortcomings .
for example if I'd take this approach, what happens when I specify the minimum and maximum range to be like 0.0001 and 0.01 ?
Or if I wanted to set steps like 0.01 then what could I do in this regard?
At first it struck me, that I can set the minimum and maximum range to an equivalent integer range,
like for the 0.0001 and 0.01 I would enter, 1 and 1000000 respectively, this way, the ratio is the same, and the step is 0.0001!
but this was proved to be wrong and not working!
the math was like :

int ratio = min/max;
step = .0001
so the

minimum_integer = 1;
maximum_integer = ratio * 10000 ;
Now what happens if I try to increase or decrease the step? in the previous example the minimum and the stepsize were the same, so no problem. but lets consider another example.
consider instead of 0.0001, I want the steps to be .000001 or be like 0.01? (our minimum is still 0.0001)

step = 0.000001;
minimum_integer = 1;
maximum_integer = ratio * 1000000;
Now if I do it this way, the minimum is lost, it no more starts from where it should start.
So in a nutshell I am confused how to map the difference !

or come up with a QDoubleSlider that works.
Any help in this regard is greatly appreciated.

Radek
21st October 2015, 17:35
IMO, Qt itself does not implement double sliders. Qwt does

http://qwt.sourceforge.net/class_qwt_slider.html

and if look at the link, Qwt implements more: for example a logarithmic scale. But this needs installing Qwt with all bells and whistles around. Also, pay attention to versions of Qwt: some versions need Qt5, some needs Qt 5.3 etc.