欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

QT QML 练习 4

最编程 2024-10-16 07:06:29
...
import QtQuick Rectangle { id: root width: 600 height: 300 Text { // (1) identifier id: thisLabel // 设置宽度和高度 width: 150 height: 100 // (2) set x- and y-position x: 24 y: 100 Rectangle { anchors.fill: parent color: "yellow" z: parent.z - 1 } // (4) custom property property int times: 24 // (5) property alias property alias anotherTimes: thisLabel.times // (6) set text appended by value text: "thisLabel " + anotherTimes // (7) Font is a grouped property font.family: "Ubuntu" font.pixelSize: 16 // (8) KeyNavigation is an attached property KeyNavigation.tab: thatLabel // (9) Signal handler for property changes onHeightChanged: console.log('height:', height) // Focus is needed to receive key events focus: true color: focus ? "red" : "black" } Text { id: thatLabel // 设置与 thisLabel 相同的宽度和高度 width: thisLabel.width height: thisLabel.height // 设置位置在 thisLabel 右边,并有 20 像素的间距 x: thisLabel.x + thisLabel.width + 20 y: thisLabel.y Rectangle { anchors.fill: parent color: "pink" z: parent.z - 1 } text: "thatLabel" font.family: "Ubuntu" font.pixelSize: 16 focus: !thisLabel.focus KeyNavigation.tab: thisLabel color: focus ? "red" : "black" } }