Results 1 to 7 of 7

Thread: Reversing the arrows in a QSpinBox

  1. #1
    Join Date
    Jan 2009
    Posts
    34
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Reversing the arrows in a QSpinBox

    How can I "flip" the arrows in a QSpinBox so that when you push down, the number increases and when you push up, the number decreases?

    I want to use the spinbox to set depth-value so my users found it more intuitive that down would be an increase of depth.

    I have subclassed the QSpinBox (actually a QDoubleSpinBox) and overridden the wheelEvent so that one is taken care of.

    I could look for mousepress and see if the mouse is inside the up or down arrow, maybe, but when the value is 0 (minValue), the down-arrow is gray, so just overriding the values here would not be any good. I want the up-arrow to be gray when value is at minValue.

    I've tried googling for this and the closest I've come is to completely redefine the QStyle painting routine. I found this also in "C++ GUI programming with Qt 4". This seemed overly complex and I don't want to redefine the style if this means that I would set the spinBox style to something that may be unlike the native look in different OS'es.

    Is there any painting routine I could relatively easily override where I just reposition the arrows? Or any other place I should look?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reversing the arrows in a QSpinBox

    Reimplement QAbstractSpinBox::stepBy() :
    Qt Code:
    1. void MySpinbox::stepBy(int step) {
    2. QSpinBox::stepBy(-step);
    3. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2009
    Posts
    34
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Reversing the arrows in a QSpinBox

    Thanks, but it did not work for the extreme values. When the value is 0.0, the step-function is prevented. I will look more into this. Also the problem with the gray arrow was still there

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reversing the arrows in a QSpinBox

    Let's try something else then. Reimplement valueFromText and textFromValue to work on negative numbers and set your maximum as 0 and your minimum as -something. Then other things should work properly.

    Qt Code:
    1. double MySpinbox::valueFromText(const QString &text) const { return -QDoubleSpinBox::valueFromText(text); }
    2. QString MySpinbox::textFromValue(double value) const { return QDoubleSpinBox::textFromValue(-value); }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    zarkzervo (2nd March 2011)

  6. #5
    Join Date
    Jan 2009
    Posts
    34
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Reversing the arrows in a QSpinBox

    This seems to fix it for the textFromValue-part, but it looks like the validator prevents the input of positive numbers when I have a range of [-45.0, 0.0]

    I will look into that. I'm much closer to this working now than a few hours ago. Thanks!

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Reversing the arrows in a QSpinBox

    You can reimplement validate() for that.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Jan 2009
    Posts
    34
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Reversing the arrows in a QSpinBox

    I also subclassed QDoubleSpinBox to override the scrolling function.

Similar Threads

  1. how to customize arrows of QScrollBar ??
    By kunalnandi in forum Qt Programming
    Replies: 0
    Last Post: 24th March 2009, 06:05
  2. Docking Arrows
    By asriniva in forum Qt Programming
    Replies: 1
    Last Post: 24th March 2009, 01:08
  3. auto-repeating arrows
    By skrzypu in forum Qt Programming
    Replies: 0
    Last Post: 15th October 2008, 10:32
  4. stackedWidget with arrows
    By Zergi in forum Newbie
    Replies: 2
    Last Post: 16th July 2008, 11:20
  5. Remove QSpinbox up/down arrows
    By SailinShoes in forum Qt Programming
    Replies: 7
    Last Post: 12th March 2008, 21:40

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.