属性
- id是用于引用QML文件中的元素,id在文档中是唯一的,不能重置为其他的值。
- 属性可以设置值,具体取决于其类型,如果没有属性指定值,将使用默认的初始值。
- 属性可以依赖于一个或者多个其他的属性这称之为绑定。
- 可以使用property限定符向元素添加新属性,后跟类型,名称和可选的初始值
property <类型><名称>:<值> - 声明属性的另一种重要方式是使用别名关键字(property alias<名称>:<引用>
- 基于inti的值将自动转化为字符串类型每次times属性更改时都会更新文本。
- 编写grouped property的另外一种方法是font{family:"宋体“;pixelSize:24}.
- 快速切换焦点。
- 可以为属性提供处理程序,属性更改后被调用。
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import './JieJs.js' as Jie
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
Text {
id: thislabe
x: 24 ; y: 16
height: 2 * width
property int times: 24
property alias anotherTimer: thislabe.times
text:"thislabe" + anotherTimer
font.family: "宋体"
font.pixelSize: 24
KeyNavigation.tab: thatLabel
onHeightChanged: console.log('height:',height)
focus: true
color: focus ? "red" : "black"
}
Text {
id: thatLabel
text: "thatLabel"
focus: !thislabe.focus
KeyNavigation.tab: thislabe
color: focus ? "red" : "black"
}
}