Results 1 to 4 of 4

Thread: QSpinBox on_valueChanged

  1. #1
    Join Date
    Aug 2008
    Location
    Cherry Hill, NJ USA
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QSpinBox on_valueChanged

    How can I distinguish between the user changing the value of a spin box and the program changing the value? (Different things happen in the two cases...)

    A workaround is to test whether, in the on_valueChanged() method, the spin box value matches the current value of the variable it's setting, but this adds overhead I would like to avoid.

    Thanks,
    Martin

  2. #2
    Join Date
    Jan 2008
    Posts
    56
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QSpinBox on_valueChanged

    Maybe http://doc.trolltech.com/4.4.1/qabst...ditingFinished is your friend.

    Regards,

    Rainer

  3. #3
    Join Date
    Aug 2008
    Location
    Cherry Hill, NJ USA
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSpinBox on_valueChanged

    Quote Originally Posted by RThaden View Post
    Maybe http://doc.trolltech.com/4.4.1/qabst...ditingFinished is your friend.

    Regards,

    Rainer
    Hi Rainer,

    That was an interesting possibility. I don't think I gave enough information in the original question. Basically the program needs to take an action on each value change, rather than when the edit is entirely complete.

    So what I need is a way to either cause on_valueChanged events to only occur due to user input, or to check within on_valueChanged whether the user or the program caused the change.

    Thanks,
    Martin

  4. #4
    Join Date
    Aug 2008
    Location
    Cherry Hill, NJ USA
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Lightbulb Re: QSpinBox on_valueChanged

    I figured out an approach, but didn't get around to posting it. Basically, I wanted to have a spinBox and a slider "coupled" so that, if one is moved, the other changes appropriately. However, changing the spinBox programatically because the user changed the slider position or clicked on a button also invokes the on_ method for the spinBox, causing the value to be "stuck".

    All it took was a flag to indicate whether the user changed the value via the slider or buttons; the flag is set to true in the slider and button on_ slots. If the flag says the user didn't change the value, i.e. it was changed programatically, the on_ slot for the spinBox doesn't do anything.

    Martin

Similar Threads

  1. QSpinBox or QLabels
    By ToddAtWSU in forum Qt Programming
    Replies: 10
    Last Post: 27th November 2007, 20:10
  2. eventFilter and clicking inside QSpinBox
    By T4ng10r in forum Qt Programming
    Replies: 2
    Last Post: 6th March 2007, 21:02
  3. QSpinBox and setStylesheet problem
    By Ace-X in forum Qt Programming
    Replies: 2
    Last Post: 19th January 2007, 11:21
  4. QSpinBox with checkbox
    By :db:sStrong in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2007, 13:22
  5. Problem reimplementing QSpinBox in a custom widget
    By hvengel in forum Qt Programming
    Replies: 1
    Last Post: 30th March 2006, 08:12

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.