I have an Item
that is a little large. I want to resize it when dragging and ensure that the center is always dragged. The following is a trial (In order for simplicity, I don't set the center of the Item
to the mouse position here, neither do I change the size.), however the position x
will be reset immediately after I change it. Is there any way to avoid this.
import QtQuick 2.7
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello Quick")
Rectangle{
id: item_
width: 300
height: 300
color: "red"
MouseArea{
id: drag_
anchors.fill: parent
drag.target: item_
}
states: State{
when: drag_.drag.active
PropertyChanges {
target: item_
x: 100
y: 100
}
}
onXChanged: console.log("item_.x: ", x)
}
}
The output:
qml: item_.x: 100
qml: item_.x: 0
qml: item_.x: 1
qml: item_.x: 2
qml: item_.x: 3
qml: item_.x: 4
qml: item_.x: 5
qml: item_.x: 6
qml: item_.x: 7
qml: item_.x: 8
qml: item_.x: 10