import QtQuick 2.15

Window {
width: 400
height: 600
visible: true

Rectangle {
x: 100
y: 100
width: 100
height: 100
color: "blue"
focus: true // 获取焦点,如果获取键盘的事件

MouseArea {
anchors.fill: parent
onClicked: {
console.log("clicked ...")
}
}

// 方向键 右侧
Keys.onRightPressed: {
console.log("right pressed ...")
}

// enter 会车键
Keys.onReturnPressed: {
console.log("return pressed ...")
}
}
}

qml教程-3-Item,Rectangle_前端