Results 1 to 12 of 12

Thread: SpinBox like a slider

  1. #1
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default SpinBox like a slider

    Hi all,
    QDoubleSpinBox is nice but contains some feature who is bad for a soft.
    The idea is to have a QDoubleSpinBox who wors like a slider so it's like a button who show the value but when stay clicked on it it becomes a slider and if you double click on it, it become a text-edit to change the value by hand.And that should allow to use the dot as separator too : "3,14"->"3.14".
    This is the idea but I don't know how to achieve that correctly because it's not really a push button, it's not really a QTextEdit and it's not really a slider...
    Thanks for the help

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SpinBox like a slider

    One thing you could try:

    Create a widget that either subclasses QStackedWidget or contains one.
    Put a slider and a QLineEdit into the stacked widget.

    Implement mouseDoubleClicked() so that it switches from the slider to the line edit.
    When the input of the line edit is finished, switch back

    Cheers,
    _

  3. #3
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SpinBox like a slider

    I didn't knew QStackedWidget, I tried and the switch works nicely but one problem remains who is the slider who needs to be like a button, so the slider must works on all the surface of the widget and not just the bar of the slider like the basic slider widget does.
    The goal is to have a widget of this style : http://uppix.com/f-spinbox_slider5271107600146aae.png.
    The stylesheet is the best way to achieve that or a better solution exist ?
    Thanks for the help
    Last edited by Alundra; 30th October 2013 at 13:58.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SpinBox like a slider

    I am afraid I don't understand either the problem, nor how the linked image has anything to do with a slider.

    Cheers,
    _

  5. #5
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SpinBox like a slider

    It's fast but you can see here :
    http://www.youtube.com/watch?v=PjSFbPv3SLc
    at 2min01s

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SpinBox like a slider

    In this case it is probably easier to implement your own widget.

    Maybe starting with a QDoubleSpin box as a base class, set it to read-ony at the beginning, switching to read/write when double clicked.
    Normal mouse handling for the "slider" effect.

    Cheers,
    _

  7. #7
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SpinBox like a slider

    Ok, thanks for the tip, but one problem remains, when you edit the value you can write "10.0001" but that will be truncated because of decimals allowed.
    Is it possible to counter that, to set the number of decimals based on the value ?
    Is the virtual valueFromText function the best to have that correctly ?
    Thanks for the help

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SpinBox like a slider

    valueFromText sounds like a good choice.

    Cheers,
    _

  9. #9
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SpinBox like a slider

    The real problem now is how to allow the lineEdit() of QDoubleSpinBox to write infinite decimals before the trick of setDecimals.
    I tried some method but no one worked, sounds like not so easy that sounds.

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: SpinBox like a slider

    The line edit is probably using a QDoubleValidator as its validator(), you might need a different one.

    Cheers,
    _

  11. #11
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SpinBox like a slider

    I use this one :
    const QString DecimalPointString = ( LocalDecimalPoint != "." ) ? LocalDecimalPoint : "";
    lineEdit()->setValidator( new QRegExpValidator( QRegExp( "-?[0-9]*[." + DecimalPointString + "]?[0-9]{,2}" ), this ) );
    He works good to have only number, - and . but it doesn't remove the block of decimals.

  12. #12
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: SpinBox like a slider

    Using :
    lineEdit()->setValidator( new QRegExpValidator( QRegExp( "-?[0-9]*[." + DecimalPointString + "]?[0-9]{,}" ), this ) );
    That works to not have limit on decimals when write on the LineEdit but I have a last prob.
    // Set default decimals.
    setDecimals( 15 );

    // Set default min/max.
    setMinimum( -DBL_MAX );
    setMaximum( +DBL_MAX );
    This code make the lineEdit really big on the width.I can't have it little.
    Maybe a fix exist ?
    Thanks for the help

Similar Threads

  1. Dynamic label to right of slider resizes slider
    By zenzero-2001 in forum Qt Programming
    Replies: 2
    Last Post: 3rd October 2013, 10:11
  2. Replies: 2
    Last Post: 21st March 2010, 09:01
  3. Getting the value from a spinbox
    By X-man in forum Newbie
    Replies: 14
    Last Post: 28th September 2007, 01:27
  4. Shape changing under other tab using slider/spinbox
    By kramed in forum Qt Programming
    Replies: 2
    Last Post: 7th August 2007, 19:59
  5. spinbox
    By mickey in forum Newbie
    Replies: 5
    Last Post: 26th July 2006, 19:09

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.