Results 1 to 7 of 7

Thread: QSpinbox: change speed of increments when holding button

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

    Default QSpinbox: change speed of increments when holding button

    Hi all,

    I would like to change the speed of the increments when clicking and holding a spinbutton of a QSpinbox. I don't want to accelerate it over time, I just want to change the default speed which is used to trigger the increments. I didn't find any property which controls that.

    Any idea?

    Regards,

    Rainer

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QSpinbox: change speed of increments when holding button

    It can be done with a custom style. Reimplement QStyle::styleHint(SH_SpinBox_ClickAutoRepeatRate) and return suitable time in ms. Probably you want to use a [WIKI]proxy style[/WIKI] to do that.
    J-P Nurmi

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

    RThaden (20th September 2008)

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

    Default Re: QSpinbox: change speed of increments when holding button

    Thanks jpn for your valuable reply. I would have never come up myself with that solution.

    I implemented it like this in my subclassed style from ProxyStyle:
    Qt Code:
    1. class HD2Style : public ProxyStyle
    2. {
    3. public:
    4. explicit HD2Style(const QString& baseStyle) : ProxyStyle(baseStyle)
    5. {
    6. }
    7.  
    8. int styleHint(StyleHint hint, const QStyleOption* option=0, const QWidget* widget=0, QStyleHintReturn* returnData = 0) const
    9. {
    10. switch(hint)
    11. {
    12. case QStyle::SH_SpinBox_KeyPressAutoRepeatRate:
    13. case QStyle::SH_SpinBox_ClickAutoRepeatRate:
    14. return 100;
    15. case QStyle::SH_SpinBox_ClickAutoRepeatThreshold:
    16. return 500;
    17. default:
    18. return ProxyStyle::styleHint(hint, option, widget, returnData);
    19. }
    20. }
    21.  
    22. };
    To copy to clipboard, switch view to plain text mode 

    It works like a charm for the ClickAutoRepeat, however it doesn't for KeyPressAutoRepeat. That is, the speed of the auto repeat when I press Cursor-Up when the line edit of the spin box has the focus is not changed.

    Did I miss something?

    Regards,

    Rainer

  5. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QSpinbox: change speed of increments when holding button

    I don't see QStyle::SH_SpinBox_KeyPressAutoRepeatRate being used for anything at all. Have you tried adjusting QApplication::keyboardInputInterval?
    J-P Nurmi

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

    Default Re: QSpinbox: change speed of increments when holding button

    You're right, ClickAutoRepeatRate is used for a timer, but SH_SpinBox_KeyPressAutoRepeatRate is never used.

    keyboardInputInterval doesn't work.
    The documentation says about it
    This property holds the time limit in milliseconds that distinguishes a key press from two consecutive key presses.

    The default value on X11 is 400 milliseconds.
    I found that it is used e.g. in keboardSearch, where a new search is triggered 400ms after the last key was released.

    I searched through the Qt code and found QAbstractButton::setAutoRepeatInterval(). I assume that the spinButtons use it. However, I am not sure, how to apply that to the QSpinBox. I already have QSpinBox subclassed but I didn't find an access to the buttons.

    I will ask for support at Trolltech and report what they said about it.

    Regards,

    Rainer

  7. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QSpinbox: change speed of increments when holding button

    Unfortunately QSpinBox buttons aren't QAbstractButtons. They are just "primitive elements" drawn by the style.
    J-P Nurmi

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

    Default Re: QSpinbox: change speed of increments when holding button

    Trolltech has answered on my mail:

    We have read your email but require more time to deal with it. We have
    assigned it the issue number #227937. Please use this number if you email
    us about the issue.
    I didn't find that issue in the bugtracker yet. Maybe it is not yet published. So, I'll have to wait ...
    Thanks for sharing your knowledge, jpn.

    Regards,

    Rainer

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.