Results 1 to 2 of 2

Thread: Does Qt has a doubleSlider which works with double values?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2012
    Location
    Iran
    Posts
    34
    Thanks
    33
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Does Qt has a doubleSlider which works with double values?

    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 :
    Qt Code:
    1. class DoubleSlider : public QSlider {
    2. Q_OBJECT
    3.  
    4. public:
    5. DoubleSlider(QWidget *parent = 0) : QSlider(parent) {
    6. connect(this, SIGNAL(valueChanged(int)),
    7. this, SLOT(notifyValueChanged(int)));
    8. }
    9.  
    10. signals:
    11. void doubleValueChanged(double value);
    12.  
    13. public slots:
    14. void notifyValueChanged(int value) {
    15. double doubleValue = value / 10.0;
    16. emit doubleValueChanged(doubleValue);
    17. }
    18. };
    To copy to clipboard, switch view to plain text mode 
    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 :
    Qt Code:
    1. int ratio = min/max;
    2. step = .0001
    To copy to clipboard, switch view to plain text mode 
    so the
    Qt Code:
    1. minimum_integer = 1;
    2. maximum_integer = ratio * 10000 ;
    To copy to clipboard, switch view to plain text mode 
    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)
    Qt Code:
    1. step = 0.000001;
    2. minimum_integer = 1;
    3. maximum_integer = ratio * 1000000;
    To copy to clipboard, switch view to plain text mode 
    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.

  2. #2
    Join Date
    Apr 2013
    Location
    Prague
    Posts
    258
    Thanks
    3
    Thanked 65 Times in 59 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Does Qt has a doubleSlider which works with double values?

    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.

  3. The following user says thank you to Radek for this useful post:

    Hossein (21st October 2015)

Similar Threads

  1. Replies: 4
    Last Post: 22nd August 2013, 17:09
  2. Replies: 2
    Last Post: 28th August 2012, 03:53
  3. Replies: 2
    Last Post: 23rd February 2012, 02:11
  4. Replies: 3
    Last Post: 6th July 2011, 07:59
  5. Progress Bar with double values
    By ^NyAw^ in forum Qt Programming
    Replies: 8
    Last Post: 23rd March 2007, 16:37

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.