diff options
author | Frederik Gladhorn <frederik.gladhorn@remarkable.com> | 2020-03-28 15:14:41 +0100 |
---|---|---|
committer | Frederik Gladhorn <gladhorn@kde.org> | 2020-04-02 09:29:21 +0000 |
commit | 324b0e72c647a7829251164671bd6a7586658e6c (patch) | |
tree | 836c564a7c6fd0f2b2d23b7e7f811d7374321124 /src/quick | |
parent | 38b3504e972281f4b79d78ad325686863fdafcd5 (diff) |
Fix QQuickMouseArea getting stuck in pressed state when hiding in press
In 78c1fcbc49f56463064eef738a475d9018357b24 we stopped giving the
exclusive grab to hidden or disabled items which 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 hiding 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
(cherry picked from commit 8ace780b5aa298e3c01903bfd57f766a42209191)
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/quick')
-rw-r--r-- | src/quick/items/qquickmousearea.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/quick/items/qquickmousearea.cpp b/src/quick/items/qquickmousearea.cpp index 5124802dbf..0cdd90d529 100644 --- a/src/quick/items/qquickmousearea.cpp +++ b/src/quick/items/qquickmousearea.cpp @@ -1079,6 +1079,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; |