1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| import QtQuick 2.4
import QtQuick.Controls 1.3
ApplicationWindow {
width : 800
height : 600
Item {
id: root
width: 64; height: 64
property int actX
property int actY
MouseArea {
id: mouseArea
width: 64; height: 64
anchors.centerIn: parent
drag.target: tile
onPressed: {
parent.actX = mouseX
parent.actY = mouseY
}
onReleased: {
parent.x = parent.x+mouseX-parent.actX
parent.y = parent.y+mouseY-parent.actY
}
Rectangle {
id: tile
width: 64; height: 64
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
states: State {
when: mouseArea.drag.active
ParentChange { target: tile; parent: root }
AnchorChanges { target: tile; anchors.verticalCenter: undefined; anchors.horizontalCenter: undefined }
}
}
}
}
} |
Partager