diff options
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() |