diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-04-08 20:22:10 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2022-04-11 13:44:47 +0200 |
commit | fcc3d346c8aaff74b0054974040d3c1250301563 (patch) | |
tree | 431a7139669d7d7042871c62e923c2277f0822d2 | |
parent | 05f60c329e66fd08a37c260e338c38f74e8191b5 (diff) |
Control in pressDelay Flickable: detect touch release near press pos
When a control is on a Flickable with a pressDelay, any press event from
a touch device will be replayed as a mouse event due to the delay; so it
was known already that we cannot depend on the fact that we got the
first press as a touch event when checking whether the id matches before
accepting it. So we keep the previous pos when it is a synthesized mouse
event, so that we can ensure the release is also accepted. That was in
place already; but now we no longer require that the release position is
identical to the press position: staying within a distance less than the
drag threshold is also ok. Some touchscreens are too sensitive, some
users have shaky hands, so a "tap" gesture may come with some gratuitous
TouchMove events in between the press and the release.
Amends 025f938c1b4676782674d54375e1e4e560e4b6cd
Fixes: QTBUG-102036
Fixes: QTBUG-102037
Task-number: QTBUG-77202
Change-Id: Ic48b0cca2b1c05b36429925f219d75b1b0085f69
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
-rw-r--r-- | src/quicktemplates2/qquickcontrol.cpp | 7 | ||||
-rw-r--r-- | tests/auto/qquickcontrol/tst_qquickcontrol.cpp | 7 |
2 files changed, 9 insertions, 5 deletions
diff --git a/src/quicktemplates2/qquickcontrol.cpp b/src/quicktemplates2/qquickcontrol.cpp index 08b925ae..2c9fb71f 100644 --- a/src/quicktemplates2/qquickcontrol.cpp +++ b/src/quicktemplates2/qquickcontrol.cpp @@ -179,9 +179,10 @@ bool QQuickControlPrivate::acceptTouch(const QTouchEvent::TouchPoint &point) // If the control is on a Flickable that has a pressDelay, then the press is never // sent as a touch event, therefore we need to check for this case. - if (touchId == -1 && pressWasTouch && point.state() == Qt::TouchPointReleased && - point.pos() == previousPressPos) { - return true; + if (touchId == -1 && pressWasTouch && point.state() == Qt::TouchPointReleased) { + const auto delta = QVector2D(point.pos() - previousPressPos); + if (!QQuickWindowPrivate::dragOverThreshold(delta)) + return true; } return false; } diff --git a/tests/auto/qquickcontrol/tst_qquickcontrol.cpp b/tests/auto/qquickcontrol/tst_qquickcontrol.cpp index c8d34756..df3b31c8 100644 --- a/tests/auto/qquickcontrol/tst_qquickcontrol.cpp +++ b/tests/auto/qquickcontrol/tst_qquickcontrol.cpp @@ -98,9 +98,12 @@ void tst_QQuickControl::flickable() QSignalSpy buttonClickedSpy(button, SIGNAL(clicked())); QVERIFY(buttonClickedSpy.isValid()); - QTest::touchEvent(window, touchDevice.data()).press(0, QPoint(button->width() / 2, button->height() / 2)); + QPoint p(button->width() / 2, button->height() / 2); + QTest::touchEvent(window, touchDevice.data()).press(0, p); QTRY_COMPARE(buttonPressedSpy.count(), 1); - QTest::touchEvent(window, touchDevice.data()).release(0, QPoint(button->width() / 2, button->height() / 2)); + p += QPoint(1, 1); // less than the drag threshold + QTest::touchEvent(window, touchDevice.data()).move(0, p); + QTest::touchEvent(window, touchDevice.data()).release(0, p); QTRY_COMPARE(buttonReleasedSpy.count(), 1); QTRY_COMPARE(buttonClickedSpy.count(), 1); } |