summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/widgets/qscrollbar.cpp2
-rw-r--r--tests/auto/qscrollbar/tst_qscrollbar.cpp19
2 files changed, 21 insertions, 0 deletions
diff --git a/src/gui/widgets/qscrollbar.cpp b/src/gui/widgets/qscrollbar.cpp
index 02d584c29f..0157126a88 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<QWheelEvent *>(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 54bb8d5326..d8bb79949e 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"