I have a program written in Qt, who uses QML.
I'd like to know if it is possible to know the coordinates in real time during the drag of an element.
Actually, I use a custom image that replaces the cursor, its position is updated with the coordinates of the cursor (which is hidden).
I can actually recover the position of the mouse cursor during its deplacement with "onPositionChanged" or just after a click with "onClicked."
I want also to know these coordinates during a drag, I tried with "onPressed" and "onPressAndHold" but without success, the position of the custom cursor is updated only on the click release.
Any help would be appreciated, thank you in advance.
Dragging elements changes the x
and y
properties directly so you can monitor those:
Rectangle {
id: draggable
width: 100
height: 100
onXChanged: {
if (mouseArea.drag.active) {
console.log("x=" + x)
}
}
onYChanged: {
if (mouseArea.drag.active) {
console.log("y=" + y)
}
}
MouseArea {
id: mouseArea
anchors.fill: parent
drag {
target: draggable
axis: Drag.XandYAxis
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With