add position listen

This commit is contained in:
王劲鹏 2021-06-02 11:07:44 +08:00 committed by osborn
parent 057c7aa3ef
commit a0a6ebf50d
2 changed files with 30 additions and 7 deletions

View File

@ -9,6 +9,11 @@ ApplicationWindow {
title: qsTr("Scroll")
Rectangle {
anchors.fill: parent
Rectangle {
id: root
width: 200; height: 200
color: "red"
@ -19,6 +24,15 @@ ApplicationWindow {
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)
}
}
}
}
}

View File

@ -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