У меня есть сетка 4x4, и я хочу связать нажатия клавиш со стрелками с перемещением элементов внутри сетки. Как это сделать?
Вот пример QML:
import QtQuick 1.1
Rectangle {
id: main;
width: 500; height: 500;
color: "darkgreen";
property int emptyBlock: 16;
Grid {
id: grid16;
x: 5; y: 5;
width: 490; height: 490;
rows: 4; columns: 4; spacing: 5;
Repeater {
model: 1;
Rectangle {
width: 118; height: 118; color: "darkblue";
}
}
}
Keys.onRightPressed: pressRight();
function pressRight() {
console.log("Left key pressed");
}
focus: true;
}
Обновление 1:Спасибо sebasgo и alexisdm за ответы. Если перемещение по сетке не так просто, почему у нас есть move
свойство перехода [http://qt-project.org/doc/qt-4.8/qml-grid.html#move-prop]