diff options
author | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2022-11-10 22:42:29 +0200 |
---|---|---|
committer | Tarja Sundqvist <tarja.sundqvist@qt.io> | 2022-11-10 22:42:29 +0200 |
commit | f5701f0def37fcc0c2b38ae9552eb3a896a34687 (patch) | |
tree | aa9a7ebb39bedb6794f199d94525f5ddfb696308 /src/quick/handlers | |
parent | da0aac1057552048f59075beb31861a6cc076684 (diff) | |
parent | e24effdceb3a504182ae271200408750991aa94a (diff) |
Merge remote-tracking branch 'origin/tqtc/lts-5.15.8' into tqtc/lts-5.15-opensourcev5.15.8-lts-lgpl
Change-Id: I2e0f34eea87c1393dff82f153650eccf5048248f
Diffstat (limited to 'src/quick/handlers')
-rw-r--r-- | src/quick/handlers/qquickhoverhandler.cpp | 14 | ||||
-rw-r--r-- | src/quick/handlers/qquickhoverhandler_p.h | 1 | ||||
-rw-r--r-- | src/quick/handlers/qquickpointerhandler.cpp | 24 |
3 files changed, 31 insertions, 8 deletions
diff --git a/src/quick/handlers/qquickhoverhandler.cpp b/src/quick/handlers/qquickhoverhandler.cpp index b12d85784a..3361415eac 100644 --- a/src/quick/handlers/qquickhoverhandler.cpp +++ b/src/quick/handlers/qquickhoverhandler.cpp @@ -85,8 +85,11 @@ QQuickHoverHandler::~QQuickHoverHandler() void QQuickHoverHandler::componentComplete() { - parentItem()->setAcceptHoverEvents(true); - QQuickItemPrivate::get(parentItem())->setHasHoverInChild(true); + QQuickSinglePointHandler::componentComplete(); + if (auto par = parentItem()) { + par->setAcceptHoverEvents(true); + QQuickItemPrivate::get(par)->setHasHoverInChild(true); + } } bool QQuickHoverHandler::wantsPointerEvent(QQuickPointerEvent *event) @@ -124,6 +127,13 @@ void QQuickHoverHandler::handleEventPoint(QQuickEventPoint *point) setPassiveGrab(point); } +void QQuickHoverHandler::onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point) +{ + QQuickSinglePointHandler::onGrabChanged(grabber, transition, point); + if (grabber == this && transition == QQuickEventPoint::CancelGrabPassive) + setHovered(false); +} + /*! \qmlproperty bool QtQuick::HoverHandler::hovered \readonly diff --git a/src/quick/handlers/qquickhoverhandler_p.h b/src/quick/handlers/qquickhoverhandler_p.h index 313b87217c..426372d162 100644 --- a/src/quick/handlers/qquickhoverhandler_p.h +++ b/src/quick/handlers/qquickhoverhandler_p.h @@ -78,6 +78,7 @@ protected: void componentComplete() override; bool wantsPointerEvent(QQuickPointerEvent *event) override; void handleEventPoint(QQuickEventPoint *point) override; + void onGrabChanged(QQuickPointerHandler *grabber, QQuickEventPoint::GrabTransition transition, QQuickEventPoint *point) override; private: void setHovered(bool hovered); diff --git a/src/quick/handlers/qquickpointerhandler.cpp b/src/quick/handlers/qquickpointerhandler.cpp index a6c18feafe..25c5e684b7 100644 --- a/src/quick/handlers/qquickpointerhandler.cpp +++ b/src/quick/handlers/qquickpointerhandler.cpp @@ -207,9 +207,11 @@ void QQuickPointerHandler::setCursorShape(Qt::CursorShape shape) return; d->cursorShape = shape; d->cursorSet = true; - QQuickItemPrivate *itemPriv = QQuickItemPrivate::get(parentItem()); - itemPriv->hasCursorHandler = true; - itemPriv->setHasCursorInChild(true); + if (auto *par = qmlobject_cast<QQuickItem *>(parent())) { + QQuickItemPrivate *itemPriv = QQuickItemPrivate::get(par); + itemPriv->hasCursorHandler = true; + itemPriv->setHasCursorInChild(true); + } emit cursorShapeChanged(); } @@ -220,9 +222,11 @@ void QQuickPointerHandler::resetCursorShape() return; d->cursorShape = Qt::ArrowCursor; d->cursorSet = false; - QQuickItemPrivate *itemPriv = QQuickItemPrivate::get(parentItem()); - itemPriv->hasCursorHandler = false; - itemPriv->setHasCursorInChild(itemPriv->hasCursor); + if (auto *parent = parentItem()) { + QQuickItemPrivate *itemPriv = QQuickItemPrivate::get(parent); + itemPriv->hasCursorHandler = false; + itemPriv->setHasCursorInChild(itemPriv->hasCursor); + } emit cursorShapeChanged(); } @@ -457,6 +461,14 @@ void QQuickPointerHandler::classBegin() void QQuickPointerHandler::componentComplete() { + Q_D(const QQuickPointerHandler); + if (d->cursorSet) { + if (auto *parent = parentItem()) { + QQuickItemPrivate *itemPriv = QQuickItemPrivate::get(parent); + itemPriv->hasCursorHandler = true; + itemPriv->setHasCursorInChild(true); + } + } } QQuickPointerEvent *QQuickPointerHandler::currentEvent() |