TEXT元素
本文出自《Qt5CadaquesInChinese 》
import QtQuick 2.5
import QtQuick.Window 2.2
Rectangle {
width: 360
height: 360
Text {
id: label
x: 0; y: -300
property int spacePresses: 0
text: "Space pressed: " + spacePresses + " times"
width: 360; height: 360
// 省略文本位置,此處爲中間省略
//elide: Text.ElideMiddle
// red sunken text styling
//字的樣式
style: Text.Outline
//樣式顏色
styleColor: '#FF4444'
//字體大小
font.pixelSize: 20
//文本顯示的位置
verticalAlignment: Text.AlignBottom
//並且希望使用文字換行的方
//式顯示所有的文本,你可以使用wrapMode屬性(這個屬性只在明確設置了寬度後才生效)
wrapMode: Text.WordWrap
onTextChanged: console.log("text changed to:", text)
//接收按鍵
focus: true
//
Keys.onSpacePressed: {
increment()
}
Keys.onDigit1Pressed: {
increment()
}
Keys.onUpPressed: {
increment()
}
(text: "Space pressed:" + spacePresses + "times")被銷燬
Keys.onEscapePressed: {
label.text = ''
}
function increment() {
spacePresses = spacePresses + 1
}
}
MouseArea {
anchors.fill: parent
onClicked: {
Qt.quit();
}
}
}