import QtQuick 2.0
import QtQuick.Controls 1.1
Rectangle {
width: 320;
height: 480;
color: "gray";
focus: true;
Keys.enabled: true;
Keys.onEscapePressed: {
Qt.quit();
}
Keys.forwardTo: [moveText, moveText1]; // 将不处理的按键,传递到第二个控件
Text {
id: moveText;
x: 20;
y: 20;
width: 200;
height: 30;
text: "Moving Text";
color: "blue";
//focus: true;
font { bold: true; pixelSize: 24;}
Keys.enabled: true;
Keys.onPressed: {
switch(event.key){
case Qt.Key_Left:
x -= 10;
break;
case Qt.Key_Right:
x += 10;
break;
default:
return;
}
event.accepted = true;
}
}
Text {
id: moveText1;
x: 20;
y: 20;
width: 200;
height: 30;
text: "Moving Text";
color: "blue";
//focus: true;
font { bold: true; pixelSize: 24;}
Keys.enabled: true;
Keys.onPressed: {
switch(event.key){
case Qt.Key_Down:
y += 10;
break;
case Qt.Key_Up:
y -= 10;
break;
default:
return;
}
event.accepted = true;
}
}
}