Move rectangle with arrow keys
Solved
QML and Qt Quick
-
How would I use the arrow keys to move rectangle?
Rectangle { id:point anchors.centerIn: parent width: 20 height: 20 opacity: 0.2 MouseArea { anchors.fill: parent drag.target: root onPositionChanged: { if(drag.active) { dragged() } } } Keys.onPressed: { if (event.key == Qt.Key_Left) { console.log("move left"); event.accepted = true; point.x-=1; } } }
-
@neda AFAIK an anchored Item will not move unless you free it.
Rectangle { id:point anchors.centerIn: parent // <- remove this width: 20 ...
I don't understand what you are trying to do inside canvas. But for a test I tried the rest of the code. It works by applying the above said changes. It will move the first Item.