PDA

View Full Version : QSpinbox: change speed of increments when holding button



RThaden
19th September 2008, 16:31
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

jpn
19th September 2008, 18:23
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 proxy style to do that.

RThaden
20th September 2008, 02:58
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:


class HD2Style : public ProxyStyle
{
public:
explicit HD2Style(const QString& baseStyle) : ProxyStyle(baseStyle)
{
}

int styleHint(StyleHint hint, const QStyleOption* option=0, const QWidget* widget=0, QStyleHintReturn* returnData = 0) const
{
switch(hint)
{
case QStyle::SH_SpinBox_KeyPressAutoRepeatRate:
case QStyle::SH_SpinBox_ClickAutoRepeatRate:
return 100;
case QStyle::SH_SpinBox_ClickAutoRepeatThreshold:
return 500;
default:
return ProxyStyle::styleHint(hint, option, widget, returnData);
}
}

};


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

jpn
20th September 2008, 10:16
I don't see QStyle::SH_SpinBox_KeyPressAutoRepeatRate being used for anything at all. Have you tried adjusting QApplication::keyboardInputInterval?

RThaden
20th September 2008, 13:15
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

jpn
21st September 2008, 19:32
Unfortunately QSpinBox buttons aren't QAbstractButtons. They are just "primitive elements" drawn by the style.

RThaden
22nd September 2008, 12:53
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