From 7465329fe18315d50c4e6325cfd7c9fc1e203812 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 25 Oct 2017 13:24:49 +0200 Subject: 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 --- .../qabstractbutton/tst_qabstractbutton.cpp | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'tests') 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() { -- cgit v1.2.3