summaryrefslogtreecommitdiff
path: root/dev-qt/qtdeclarative/files/qtdeclarative-5.14.2-QQuickMouseArea-stuck-in-pressed-state.patch
blob: 1dd0ff1155de9b44e4ded91bdedec490863ad973 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
From 8ace780b5aa298e3c01903bfd57f766a42209191 Mon Sep 17 00:00:00 2001
From: Frederik Gladhorn <frederik.gladhorn@remarkable.com>
Date: Sat, 28 Mar 2020 15:14:41 +0100
Subject: [PATCH] Fix QQuickMouseArea getting stuck in pressed state when
 hiding in press
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

In 78c1fcbc49f56463064eef738a475d9018357b24 we stopped giving the
exclusive grab to hidden or disabled items with is good. But the change
did not take into consideration how mouse area handles its internal
state.

As a simple example: A mouse area that would set itself hiddin in the
press handler, would continue to have d->pressed == true, which means it
would not react to any future press events.

The fix is to let mouse area check in its change handler whether it has
become invisible.
The test also checks that enabled behaves the same way. There is no
action needed, since mouse area does completely custom handling of
enabled (maybe something to fix in Qt 6), disabling a mouse area doesn't
disable its children for example, it doesn't invoke
QQuickItem::setEnabled at all. Due to this circumventing the common
behavior, by chance disabling a mouse area in the on pressed handler
works.

Fixes: QTBUG-74987
Change-Id: Idb8499b3e5bcb744fbba203fdea5c46695bd5077
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
---
 src/quick/items/qquickmousearea.cpp                |  6 ++++
 3 files changed, 80 insertions(+)
 create mode 100644 tests/auto/quick/qquickmousearea/data/settingHiddenInPressUngrabs.qml

diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp
index 368379f5c40..dc60712a9cd 100644
--- a/src/quick/items/qquickmousearea.cpp
+++ b/src/quick/items/qquickmousearea.cpp
@@ -1083,6 +1083,12 @@ void QQuickMouseArea::itemChange(ItemChange change, const ItemChangeData &value)
             }
             setHovered(!d->hovered);
         }
+        if (d->pressed && (!isVisible())) {
+            // This happens when the mouse area sets itself disabled or hidden
+            // inside the press handler. In that case we should not keep the internal
+            // state as pressed, since we never became the mouse grabber.
+            ungrabMouse();
+        }
         break;
     default:
         break;
-- 
2.16.3