QML TEXT元素

来源:互联网 发布:女权运动 知乎 编辑:程序博客网 时间:2024/06/05 09:15

TEXT元素

本文出自《Qt5CadaquesInChinese 》

import QtQuick 2.5import 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();        }            }                 }
原创粉丝点击