QPushButton: emit released signal when mouse dragged out of bounds

After special processing for hover, QPushButton::mouseMoveEvent()
needs to call the base class function, like every virtual override
should, to continue processing other logic.  Amends
3310e13a17d2249a86fa533e350744c5593be54f

Fixes: QTBUG-97937
Pick-to: 6.0 6.2
Change-Id: Ic2e111d6c38371e0aa04423f5fb26c52717bf5fb
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
ChunLin Wang 2021-11-03 17:59:03 +08:00
parent f28e161361
commit 62b7130423
2 changed files with 33 additions and 0 deletions

View File

@ -525,6 +525,8 @@ void QPushButton::mouseMoveEvent(QMouseEvent *e)
d->hovering = hit;
}
}
QAbstractButton::mouseMoveEvent(e);
}
/*!

View File

@ -74,6 +74,7 @@ private slots:
void emitReleasedAfterChange();
void hitButton();
void iconOnlyStyleSheet();
void mousePressAndMove();
protected slots:
void resetCounters();
@ -753,5 +754,35 @@ void tst_QPushButton::iconOnlyStyleSheet()
QVERIFY(QTest::qWaitForWindowExposed(&pb));
}
/*
Test that mouse has been pressed,the signal is sent when moving the mouse.
QTBUG-97937
*/
void tst_QPushButton::mousePressAndMove()
{
QPushButton button;
button.setGeometry(0, 0, 20, 20);
QSignalSpy pressSpy(&button, &QAbstractButton::pressed);
QSignalSpy releaseSpy(&button, &QAbstractButton::released);
QTest::mousePress(&button, Qt::LeftButton);
QCOMPARE(pressSpy.count(), 1);
QCOMPARE(releaseSpy.count(), 0);
// mouse pressed and moving out
QTest::mouseMove(&button, QPoint(100, 100));
// should emit released signal when the mouse is dragged out of boundary
QCOMPARE(pressSpy.count(), 1);
QCOMPARE(releaseSpy.count(), 1);
// mouse pressed and moving into
QTest::mouseMove(&button, QPoint(10, 10));
// should emit pressed signal when the mouse is dragged into of boundary
QCOMPARE(pressSpy.count(), 2);
QCOMPARE(releaseSpy.count(), 1);
}
QTEST_MAIN(tst_QPushButton)
#include "tst_qpushbutton.moc"