summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2012-09-25 10:54:11 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2012-09-26 19:06:47 +0200
commitaec5b76b51fb1895f275ac4d413cc040cf88d519 (patch)
tree57b5f8d58778bb5d9c29b769e0b729888cee838d
parentd535c910e443b974f0070cea2b3b000190450268 (diff)
[QTBUG-27308][QTBUG-21534] Don't mouse-wheel-scroll QScrollBar when disabled
This fixes a regression introduced in Qt 4 commit e855b199319c932f2e9500235775f961bc32e41a. The problem was that by handling the wheel event in event() instead of wheelEvent(), we lack the guard clause in QWidget that doesn't even call the handler if the widget is disabled, and the code didn't handle this itself. Fix by reimplementing wheelEvent() instead, which we can now do because we can break BC. This commit just moves the code. Another commit will clean up the implementation of wheelEvent(). Task-number: QTBUG-27308 Reported-by: chenjiexin Task-number: QTBUG-21534 Reported-by: Martin Koller Change-Id: Ibe6b89a81fe889f839c205b859a1492b39a4ddc3 Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
-rw-r--r--src/widgets/widgets/qscrollbar.cpp20
-rw-r--r--src/widgets/widgets/qscrollbar.h3
-rw-r--r--tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp19
3 files changed, 34 insertions, 8 deletions
diff --git a/src/widgets/widgets/qscrollbar.cpp b/src/widgets/widgets/qscrollbar.cpp
index efb17afedb..9ef56b7f95 100644
--- a/src/widgets/widgets/qscrollbar.cpp
+++ b/src/widgets/widgets/qscrollbar.cpp
@@ -476,8 +476,18 @@ bool QScrollBar::event(QEvent *event)
if (const QHoverEvent *he = static_cast<const QHoverEvent *>(event))
d_func()->updateHoverControl(he->pos());
break;
+ default:
+ break;
+ }
+ return QAbstractSlider::event(event);
+}
+
+/*!
+ \reimp
+*/
#ifndef QT_NO_WHEELEVENT
- case QEvent::Wheel: {
+void QScrollBar::wheelEvent(QWheelEvent *event)
+{
event->ignore();
// override wheel event without adding virtual function override
QWheelEvent *ev = static_cast<QWheelEvent *>(event);
@@ -492,14 +502,8 @@ bool QScrollBar::event(QEvent *event)
Q_D(QScrollBar);
if (d->scrollByDelta(ev->orientation(), ev->modifiers(), delta))
event->accept();
- return true;
- }
-#endif
- default:
- break;
- }
- return QAbstractSlider::event(event);
}
+#endif
/*!
\reimp
diff --git a/src/widgets/widgets/qscrollbar.h b/src/widgets/widgets/qscrollbar.h
index 95943f2676..48863616ff 100644
--- a/src/widgets/widgets/qscrollbar.h
+++ b/src/widgets/widgets/qscrollbar.h
@@ -67,6 +67,9 @@ public:
bool event(QEvent *event);
protected:
+#ifndef QT_NO_WHEELEVENT
+ void wheelEvent(QWheelEvent *);
+#endif
void paintEvent(QPaintEvent *);
void mousePressEvent(QMouseEvent *);
void mouseReleaseEvent(QMouseEvent *);
diff --git a/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp b/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp
index 88c498cf07..4940372db9 100644
--- a/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp
+++ b/tests/auto/widgets/widgets/qscrollbar/tst_qscrollbar.cpp
@@ -56,6 +56,9 @@ public slots:
private slots:
void scrollSingleStep();
void task_209492();
+#ifndef QT_NO_WHEELEVENT
+ void QTBUG_27308();
+#endif
private:
QScrollBar *testWidget;
@@ -143,5 +146,21 @@ void tst_QScrollBar::task_209492()
QCOMPARE(spy.count(), 1);
}
+#ifndef QT_NO_WHEELEVENT
+#define WHEEL_DELTA 120 // copied from tst_QAbstractSlider / tst_QComboBox
+void tst_QScrollBar::QTBUG_27308()
+{
+ // https://bugreports.qt-project.org/browse/QTBUG-27308
+ // Check that a disabled scrollbar doesn't react on wheel events anymore
+
+ testWidget->setValue(testWidget->minimum());
+ testWidget->setEnabled(false);
+ QWheelEvent event(testWidget->rect().center(),
+ -WHEEL_DELTA, Qt::NoButton, Qt::NoModifier, testWidget->orientation());
+ qApp->sendEvent(testWidget, &event);
+ QCOMPARE(testWidget->value(), testWidget->minimum());
+}
+#endif
+
QTEST_MAIN(tst_QScrollBar)
#include "tst_qscrollbar.moc"