平臺:qtcreator 5.12.6 win10
取材於:https://doc.qt.io/qt-5.12/qtquick-layouts-example.html 官網列子
import QtQuick 2.12
import QtQuick.Window 2.12
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
Rectangle{
width: 200
height: 100
Text {
id:text
font.pointSize: 15
anchors.centerIn: parent
text: qsTr("text")
}
// 鍵盤響應
focus: true
Keys.onPressed: {
if (event.key === Qt.Key_Return) { //約等於啓用鍵盤追蹤
text.color = "red";
event.accepted = true; //爲了讓父級不響應同一個事件
}
}
}
//鼠標響應(觸摸)
TapHandler{
onTapped: text.color="blue"
}
}