diff options
author | Sophie Kums <sophie.kums@web.de> | 2021-01-06 16:34:06 +0100 |
---|---|---|
committer | Sophie Kums <sophie.kums@web.de> | 2021-01-19 19:10:41 +0100 |
commit | aa09bea00ca88c587cfb1f56dc9a85040dd63b22 (patch) | |
tree | 9c9ea00f93acedc08ac7df8a4d9c4fc9e97f8970 /src/widgets/styles | |
parent | 65cc6ec16bd724f96007748823bb8902e3a7881b (diff) |
control scrolling of QTabBar using StyleHint
Mouse wheel/touchpad scroll signals sent to the tab bar trigger
cycling through the tabs. In applications where the tab bar is
close to "mouse click hotspots", the cursor may accidentally be
left over the tab bar instead of the main content of the window.
When the user wants to scroll up/down the main conten, the
scroll signals are thus sent to the tab bar and instead of
scrolling, the focus switches to another tab. This is
confusing to the user, because not only does the application
not carry out the desired action (scrolling through the main
content), it jumps to a different tab. Two common examples of
applications affected by this nuisance are Konsole and any kind
of browser (file browser or web browser), where the address bar
is right below the tab bar. Moreover, on macOS, scroll events
do not have an effect on the tab bar widget of the native UI.
Currently, the code makes use of preprocessor directives to
achieve consistent behavior on macOS (`#ifndef Q_OS_MAC`). This
patch implements the check of a StyleHint in order to determine
if scroll events on the tabbar should have an effect. This
approach is more consistent with Qt coding style than
OS-dependent preprocessor directives and, in addition, makes
the behavior configurable according to the user's preferences.
[ChangeLog][QtWidgets][QStyle] Added
SH_TabBar_AllowWheelScrolling as a style hint to enable/disable
cycling through tabs using the scroll wheel. This defaults to
true in all styles except the macOS one so there is no change in
existing behavior.
Change-Id: I99eeb5a1aab03cbc574fac7187d85a8a2d60cf34
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/widgets/styles')
-rw-r--r-- | src/widgets/styles/qcommonstyle.cpp | 3 | ||||
-rw-r--r-- | src/widgets/styles/qstyle.cpp | 5 | ||||
-rw-r--r-- | src/widgets/styles/qstyle.h | 1 |
3 files changed, 9 insertions, 0 deletions
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 5c5b25cc94..fd618149ac 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -5407,6 +5407,9 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget case SH_SpinBox_StepModifier: ret = Qt::ControlModifier; break; + case SH_TabBar_AllowWheelScrolling: + ret = true; + break; default: ret = 0; break; diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index 9f49a55386..c839afd639 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -2005,6 +2005,11 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment, disables this feature. This enum value has been introduced in Qt 5.12. + \value SH_TabBar_AllowWheelScrolling + Determines if the mouse wheel can be used to cycle through the tabs + of a QTabBar. + This enum value has been introduced in Qt 6.1. + \sa styleHint() */ diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h index ec13fdb80d..ba64a6b1bf 100644 --- a/src/widgets/styles/qstyle.h +++ b/src/widgets/styles/qstyle.h @@ -733,6 +733,7 @@ public: SH_ComboBox_AllowWheelScrolling, SH_SpinBox_ButtonsInsideFrame, SH_SpinBox_StepModifier, + SH_TabBar_AllowWheelScrolling, // Add new style hint values here SH_CustomBase = 0xf0000000 |