From a0a6ebf50d5fecb8a42cc36934f179ea06b99ee3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=8A=B2=E9=B9=8F?= Date: Wed, 2 Jun 2021 11:07:44 +0800 Subject: [PATCH] add position listen --- doric-Qt/example/app/test-layout.qml | 28 ++++++++++++++----- .../example/doric/resources/draggable.qml | 9 ++++++ 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/doric-Qt/example/app/test-layout.qml b/doric-Qt/example/app/test-layout.qml index cd6f72b4..0f7689d8 100644 --- a/doric-Qt/example/app/test-layout.qml +++ b/doric-Qt/example/app/test-layout.qml @@ -9,16 +9,30 @@ ApplicationWindow { title: qsTr("Scroll") Rectangle { - width: 200; height: 200 - color: "red" + anchors.fill: parent - Drag.active: dragArea.drag.active + Rectangle { + id: root - MouseArea { - id: dragArea - anchors.fill: parent + width: 200; height: 200 + color: "red" - drag.target: parent + Drag.active: dragArea.drag.active + + MouseArea { + id: dragArea + anchors.fill: parent + + drag.target: parent + + onPositionChanged: { + var positionToParent = mapToItem(root.parent, mouse.x, mouse.y) + var positionToRoot = mapToItem(root, mouse.x, mouse.y) + console.log(positionToParent, positionToRoot) + } + } } } + + } diff --git a/doric-Qt/example/doric/resources/draggable.qml b/doric-Qt/example/doric/resources/draggable.qml index 7c8af7aa..6df9d8ec 100644 --- a/doric-Qt/example/doric/resources/draggable.qml +++ b/doric-Qt/example/doric/resources/draggable.qml @@ -52,6 +52,15 @@ Rectangle { anchors.fill: parent drag.target: parent + + onPositionChanged: { + let positionToRootParent = mapToItem(root.parent, mouse.x, mouse.y) + let positionToRoot = mapToItem(root, mouse.x, mouse.y) + let xDiff = positionToRootParent.x - positionToRoot.x + let yDiff = positionToRootParent.y - positionToRoot.y + + console.log(tag, uuid + " onPositionChanged: " + xDiff + ", " + yDiff) + } } property var shadowColor