您的位置:首页 > 其它

QML TEXT元素

2017-08-23 15:42 344 查看

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();
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: