Надя Asked:2020-06-09 05:15:13 +0000 UTC2020-06-09 05:15:13 +0000 UTC 2020-06-09 05:15:13 +0000 UTC 单击矩形时如何将矩形移动到相邻单元格?qml 772 Rectangle{ id:brick width: 80; height: 80 } onClicked: qt 1 个回答 Voted Best Answer eri 2020-06-09T06:31:38Z2020-06-09T06:31:38Z 该矩形不接受点击 - 您需要拖动MouseArea. 您可以通过更改坐标来移动它x,y。它的移动方式是通过 设置Behavior的,您可以在其中指定不同的动画 import QtQuick 2.0 Rectangle { width: 240 height: 240 Rectangle { width: 80 height: 80 color: "red" MouseArea { anchors.fill: parent property var direction: 0 onClicked: { if (direction == 0) parent.x += 80 if (direction == 1) parent.y += 80 if (direction == 3) { parent.x += 80 parent.y += 80 } direction += 1 } } Behavior on x { NumberAnimation { id: bouncebehavior duration: 1000 easing { type: Easing.OutElastic amplitude: 1 period: 0.5 } } } Behavior on y { animation: bouncebehavior } } }
该矩形不接受点击 - 您需要拖动
MouseArea. 您可以通过更改坐标来移动它x,y。它的移动方式是通过 设置Behavior的,您可以在其中指定不同的动画