From a5beb5af606110df111be6e8321ebdd1c548db7f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 25 Sep 2012 11:09:05 +0200 Subject: [QTBUG-27308][QTBUG-21534] Don't mouse-wheel-scroll QScrollBar when disabled The Qt 5 fix (aec5b76) doesn't apply here, because it introduces a new symbol that might break forward compatibility if code compiled against a newer Qt 4.8 is run against an older Qt 4.8, and QScrollBar::wheelEvent() ends up being devirtualised. So copy the guard clause from QWidget::event() here. Task-number: QTBUG-27308 Reported-by: chenjiexin Task-number: QTBUG-21534 Reported-by: Martin Koller Change-Id: I5d2f823c65bae8cff33bac320c37e6496b14646c Reviewed-by: Stephen Kelly --- src/gui/widgets/qscrollbar.cpp | 2 ++ tests/auto/qscrollbar/tst_qscrollbar.cpp | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/gui/widgets/qscrollbar.cpp b/src/gui/widgets/qscrollbar.cpp index 02d584c..0157126 100644 --- a/src/gui/widgets/qscrollbar.cpp +++ b/src/gui/widgets/qscrollbar.cpp @@ -524,6 +524,8 @@ bool QScrollBar::event(QEvent *event) case QEvent::Wheel: { event->ignore(); // override wheel event without adding virtual function override + if (!isEnabled()) // don't scroll when disabled [QTBUG-27308] + return false; // normally prevented in QWidget::event() QWheelEvent *ev = static_cast(event); int delta = ev->delta(); // scrollbar is a special case - in vertical mode it reaches minimum diff --git a/tests/auto/qscrollbar/tst_qscrollbar.cpp b/tests/auto/qscrollbar/tst_qscrollbar.cpp index 54bb8d5..d8bb799 100644 --- a/tests/auto/qscrollbar/tst_qscrollbar.cpp +++ b/tests/auto/qscrollbar/tst_qscrollbar.cpp @@ -57,6 +57,9 @@ public slots: private slots: void scrollSingleStep(); void task_209492(); +#ifndef QT_NO_WHEELEVENT + void QTBUG_27308(); +#endif private: QScrollBar *testWidget; @@ -151,5 +154,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" -- cgit v0.12