Results 1 to 10 of 10

Thread: QSpinBox interval

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2010
    Posts
    7
    Qt products
    Qt4

    Default QSpinBox interval

    Hi,

    in a SpinBox you can only set an interval which is going from min to max. Is it possible to set other interval such as 1,10-20. So when you have an value of 1 and click the up arrow you get a 20. And after decreasing the 20 ther is a 1. How can I solve this problem?

    Thanks

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QSpinBox interval

    Just do whatever mapping between spinbox index and internal indexes you need to within your code. If the variable you want to wind up with a value in is called i, and the spinbox index is idx, then in your code say something like

    if (idx == 1)
    i = 1;
    else
    i = 10;

    or whatever sort of transformation makes sense.

  3. #3
    Join Date
    May 2010
    Posts
    7
    Qt products
    Qt4

    Default Re: QSpinBox interval

    But with this you can enter something wrong by writing s.th. with the keyboard to the box.

  4. #4
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QSpinBox interval

    QSpinbox don't allow You to write something wrong, i.e. letters instead of numbers etc.
    You can use QDesigner (in QCreator) and set-up spinbox like: min: 0, max: 200, singleStep: 20, but that way, in Your example next value will be 21 not 20, so I think SixDegrees suggestion is more flexible that way.

  5. #5
    Join Date
    May 2010
    Posts
    7
    Qt products
    Qt4

    Default Re: QSpinBox interval

    I have tried several things but don't get it to work. What do you mean with mapping.

  6. #6
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QSpinBox interval

    What he meant is:
    use spinbox signal valueChanged(int);
    That way each time value change You will get value in your slot. Then do something like was posted earlier, i.e. check if value is < 20 if true set spinbox value to 1, if false don't do anything or set the value Yourself. That way you can do almost anything with spinbox, i.e. setting different singleStep depending on the actual value range.

    Qt Code:
    1. if( a == 2) ui->spinBox->setValue( 20 );
    2. if( a == 19) ui->spinBox->setValue( 1 );
    To copy to clipboard, switch view to plain text mode 
    These code do the trick, paste it in slot connected to signal valueChanged(int );, a is int slot value, and ui->spinBox is a spinbox placed on a form. Range is 0,1,20-30... (by default spinbox settings)

  7. #7
    Join Date
    May 2010
    Posts
    7
    Qt products
    Qt4

    Default Re: QSpinBox interval

    Yes but with this Method you can't enter 22 or so because this is blocked. The only way is to disable KeyboardTracking.

  8. #8
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QSpinBox interval

    Simply subclass QSpinBox and reimplement stepUp() and stepDown().

  9. #9
    Join Date
    May 2010
    Posts
    7
    Qt products
    Qt4

    Default Re: QSpinBox interval

    Can you please outline how to reimplement for example stepDown? And I make my forms with QDesigner. Is it possible to place custom widgets in the Designer?

  10. #10
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QSpinBox interval

    Hmmm, forget a simple subclass.
    After looking at the source code of QAbstractSpinBox, I see it doesn't use spinUp() and spinDown() internally, instead it uses spinBy

Similar Threads

  1. QSpinBox
    By ToddAtWSU in forum Qt Programming
    Replies: 10
    Last Post: 1st September 2012, 03:36
  2. Phonon and the meta interval
    By huilui in forum Qt Programming
    Replies: 3
    Last Post: 7th February 2012, 06:08
  3. maximum text width of interval
    By osiris81 in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2010, 14:37
  4. QSpinbox
    By sonuani in forum Newbie
    Replies: 3
    Last Post: 21st March 2008, 10:36
  5. finding the time interval of executing a program
    By babu198649 in forum Qt Programming
    Replies: 1
    Last Post: 13th December 2007, 12:05

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
  •  
Qt is a trademark of The Qt Company.