[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>
This commit is contained in:
parent
d535c910e4
commit
aec5b76b51
@ -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
|
||||
|
@ -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 *);
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user