diff options
author | ChunLin Wang <wangchunlin@uniontech.com> | 2021-11-03 17:59:03 +0800 |
---|---|---|
committer | ChunLin Wang <wangchunlin@uniontech.com> | 2021-11-10 16:16:24 +0000 |
commit | 62b7130423047fc6eb1d51301f2f065a76e9e4a8 (patch) | |
tree | 0feb1279fec48fbe92b3375d3aba94c23c2caa23 /tests/auto/widgets/widgets | |
parent | f28e1613617b519ff6442607c99033291623d38f (diff) |
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>
Diffstat (limited to 'tests/auto/widgets/widgets')
-rw-r--r-- | tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp b/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp index e19264abb2..8c0eb591aa 100644 --- a/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp +++ b/tests/auto/widgets/widgets/qpushbutton/tst_qpushbutton.cpp @@ -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" |