From e0b6b27d397faac924751be8da2c781286c3f8d7 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Tue, 5 Oct 2021 15:47:06 +0200 Subject: Add style hint for preventing spin box selection on up/down MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On a mobile device, selecting text in a line edit brings up the text action popup for select/copy/cut. In a spinbox where the user changes the value using the buttons, this can be very irritating, without providing any usability - the user is unlikely to start typing, at least not without first transferring focus into the lineedit first to bring up the keyboard. This style hint allows styles to override the default behavior of QAbstractSpinBox. Implement the customization for the Android style, and add a test case for QSpinBox. [ChangeLog][QtWidgets][QStyle] A new style hint, SH_SpinBox_SelectOnStep, specifies whether pressing the up/down buttons or keys in a spinbox will automatically select the text. Fixes: QTBUG-93366 Change-Id: If06365a7c62087a2213145e13119f56544ac33b5 Reviewed-by: Tor Arne Vestbø Reviewed-by: Richard Moe Gustavsen --- src/widgets/styles/qcommonstyle.cpp | 3 +++ src/widgets/styles/qstyle.cpp | 4 ++++ src/widgets/styles/qstyle.h | 1 + 3 files changed, 8 insertions(+) (limited to 'src/widgets/styles') diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 6f6ddfec44..cdd061f8d5 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -5393,6 +5393,9 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget case SH_TabBar_AllowWheelScrolling: ret = true; break; + case SH_SpinBox_SelectOnStep: + ret = true; + break; default: ret = 0; break; diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index 8946b9d90e..b901b4b08e 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -1853,6 +1853,10 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, spinbox mouse clicks. \value SH_SpinBox_ClickAutoRepeatThreshold Auto-repeat threshold for spinbox mouse clicks. + \value SH_SpinBox_SelectOnStep Whether changing the value using + the buttons or up/down keys automatically selects the text. This enum + value has been introduced in Qt 6.3. + \value SH_ToolTipLabel_Opacity An integer indicating the opacity for the tip label, 0 is completely transparent, 255 is completely opaque. diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h index 6d094cc4f2..03f6fc1562 100644 --- a/src/widgets/styles/qstyle.h +++ b/src/widgets/styles/qstyle.h @@ -737,6 +737,7 @@ public: SH_SpinBox_StepModifier, SH_TabBar_AllowWheelScrolling, SH_Table_AlwaysDrawLeftTopGridLines, + SH_SpinBox_SelectOnStep, // Add new style hint values here SH_CustomBase = 0xf0000000 -- cgit v1.2.3