summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Moe Gustavsen <richard.gustavsen@qt.io>2017-10-25 13:24:49 +0200
committerRichard Moe Gustavsen <richard.gustavsen@qt.io>2017-11-15 10:06:16 +0000
commit7465329fe18315d50c4e6325cfd7c9fc1e203812 (patch)
treeaae82f64d6666a616bc5e7234216a6fe547c1687
parent3dab19ffed61a69166045d6e90e1e114d81f85a8 (diff)
QAbstractButton: don't clear 'pressed' flag unless left button is released
As it stood, we would set 'pressed' to false regardless of which button that was released. This would end up wrong if pressing the left button, and at the same time, did a click with the right button. This would clear the flag prematurely, and cause a release signal not to be emitted when later releasing the left button. tst_QAbstractButton: adding autotest Adding tests to simulate the bug report's cases: 1) left press button 2) click right/middle key 3) move mouse out of button's boundary 4) test if the released() signal triggered properly Taks-number: QTBUG-53244 Change-Id: Ifc0d5f52a917ac9cd2df5e86c0475abcda47e425 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
-rw-r--r--src/widgets/widgets/qabstractbutton.cpp3
-rw-r--r--tests/auto/widgets/widgets/qabstractbutton/tst_qabstractbutton.cpp32
2 files changed, 34 insertions, 1 deletions
diff --git a/src/widgets/widgets/qabstractbutton.cpp b/src/widgets/widgets/qabstractbutton.cpp
index dbd94e890d..5854472ff0 100644
--- a/src/widgets/widgets/qabstractbutton.cpp
+++ b/src/widgets/widgets/qabstractbutton.cpp
@@ -991,13 +991,14 @@ void QAbstractButton::mousePressEvent(QMouseEvent *e)
void QAbstractButton::mouseReleaseEvent(QMouseEvent *e)
{
Q_D(QAbstractButton);
- d->pressed = false;
if (e->button() != Qt::LeftButton) {
e->ignore();
return;
}
+ d->pressed = false;
+
if (!d->down) {
// refresh is required by QMacStyle to resume the default button animation
d->refresh();
diff --git a/tests/auto/widgets/widgets/qabstractbutton/tst_qabstractbutton.cpp b/tests/auto/widgets/widgets/qabstractbutton/tst_qabstractbutton.cpp
index 9efa8cf47e..bc7756d32f 100644
--- a/tests/auto/widgets/widgets/qabstractbutton/tst_qabstractbutton.cpp
+++ b/tests/auto/widgets/widgets/qabstractbutton/tst_qabstractbutton.cpp
@@ -68,6 +68,7 @@ private slots:
void shortcutEvents();
void stopRepeatTimer();
+ void mouseReleased(); // QTBUG-53244
#ifdef QT_KEYPAD_NAVIGATION
void keyNavigation();
#endif
@@ -563,6 +564,37 @@ void tst_QAbstractButton::stopRepeatTimer()
QCOMPARE(button.timerEventCount(), 0);
}
+void tst_QAbstractButton::mouseReleased() // QTBUG-53244
+{
+ MyButton button(nullptr);
+ button.setObjectName("button");
+ button.setGeometry(0, 0, 20, 20);
+ QSignalSpy spyPress(&button, &QAbstractButton::pressed);
+ QSignalSpy spyRelease(&button, &QAbstractButton::released);
+
+ QTest::mousePress(&button, Qt::LeftButton);
+ QCOMPARE(spyPress.count(), 1);
+ QCOMPARE(button.isDown(), true);
+ QCOMPARE(spyRelease.count(), 0);
+
+ QTest::mouseClick(&button, Qt::RightButton);
+ QCOMPARE(spyPress.count(), 1);
+ QCOMPARE(button.isDown(), true);
+ QCOMPARE(spyRelease.count(), 0);
+
+ QPointF posOutOfWidget = QPointF(30, 30);
+ QMouseEvent me(QEvent::MouseMove,
+ posOutOfWidget, Qt::NoButton,
+ Qt::MouseButtons(Qt::LeftButton),
+ Qt::NoModifier); // mouse press and move
+
+ qApp->sendEvent(&button, &me);
+ // should emit released signal once mouse is dragging out of boundary
+ QCOMPARE(spyPress.count(), 1);
+ QCOMPARE(button.isDown(), false);
+ QCOMPARE(spyRelease.count(), 1);
+}
+
#ifdef QT_KEYPAD_NAVIGATION
void tst_QAbstractButton::keyNavigation()
{