aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNoah Davis <noahadvs@gmail.com>2022-01-10 13:37:41 -0500
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-01-21 03:09:41 +0000
commit5d1dff31f60977ffc086217847388fc195b1f11f (patch)
tree903db29d542615f6a16a6756c47750fbc5026c34 /src
parentdef37f47b0b07070ef1395adeab092406fe13af2 (diff)
TabBar: allow wheel events to change currentIndex
Setting wheelEnabled to true allows wheel events to increment or decrement the currentIndex. We keep track of the total amount of angleDelta so that touchpads and high resolution mouse wheels don't change the currentIndex too rapidly. Fixes: QTBUG-99619 Change-Id: I9bda828338ee5136efcdd6abeca8e5be15da0822 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> (cherry picked from commit 2ead10bf55733defe58616de7fe2c28452d00c93) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/quicktemplates2/qquicktabbar.cpp23
-rw-r--r--src/quicktemplates2/qquicktabbar_p.h3
2 files changed, 26 insertions, 0 deletions
diff --git a/src/quicktemplates2/qquicktabbar.cpp b/src/quicktemplates2/qquicktabbar.cpp
index 512b917d58..f7010722b6 100644
--- a/src/quicktemplates2/qquicktabbar.cpp
+++ b/src/quicktemplates2/qquicktabbar.cpp
@@ -118,6 +118,9 @@ public:
bool updatingLayout = false;
QQuickTabBar::Position position = QQuickTabBar::Header;
+#if QT_CONFIG(wheelevent)
+ QPoint accumulatedAngleDelta;
+#endif
};
class QQuickTabBarAttachedPrivate : public QObjectPrivate
@@ -386,6 +389,26 @@ void QQuickTabBar::itemRemoved(int index, QQuickItem *item)
polish();
}
+#if QT_CONFIG(wheelevent)
+void QQuickTabBar::wheelEvent(QWheelEvent *event)
+{
+ Q_D(QQuickTabBar);
+ QQuickContainer::wheelEvent(event);
+ if (d->wheelEnabled) {
+ d->accumulatedAngleDelta += event->angleDelta();
+ int xSteps = d->accumulatedAngleDelta.x() / QWheelEvent::DefaultDeltasPerStep;
+ int ySteps = d->accumulatedAngleDelta.y() / QWheelEvent::DefaultDeltasPerStep;
+ if (xSteps > 0 || ySteps > 0) {
+ decrementCurrentIndex();
+ d->accumulatedAngleDelta = QPoint();
+ } else if (xSteps < 0 || ySteps < 0) {
+ incrementCurrentIndex();
+ d->accumulatedAngleDelta = QPoint();
+ }
+ }
+}
+#endif
+
QFont QQuickTabBar::defaultFont() const
{
return QQuickTheme::font(QQuickTheme::TabBar);
diff --git a/src/quicktemplates2/qquicktabbar_p.h b/src/quicktemplates2/qquicktabbar_p.h
index 9734d9b7db..a99fb444a5 100644
--- a/src/quicktemplates2/qquicktabbar_p.h
+++ b/src/quicktemplates2/qquicktabbar_p.h
@@ -92,6 +92,9 @@ protected:
void itemAdded(int index, QQuickItem *item) override;
void itemMoved(int index, QQuickItem *item) override;
void itemRemoved(int index, QQuickItem *item) override;
+#if QT_CONFIG(wheelevent)
+ void wheelEvent(QWheelEvent *event) override;
+#endif
QFont defaultFont() const override;