创建一个QML工程
创建QML工程时,选择创建Qt Quick项目

可视与不可视元素
使用控件前需要导入对应的模块,例如:需要使用 Controls 控件在手册内寻找其对应模块,并引入模块


可视元素为可以看到的元素,如:Button、Label
不可视元素为不可以看到的元素,如:Layout、RowLayout
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| RowLayout { Button { text: "Ok" onClicked: model.submit() } Button { text: "Cancel" onClicked: model.revert() } } ColumnLayout{ x: 150 Button { text: "Ok" onClicked: model.submit() } Button { text: "Cancel" onClicked: model.revert() } }
|

子元素列表
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| Item { anchors.fill: parent id:root
Column { id:cloumn
Rectangle{ width: 30 height: 30 color: "red" property string name: 'rect1' } Rectangle{ width: 30 height: 30 color: "blue" property string name: 'rect2'
Label{ text: 'label' } } Component.onCompleted: { console.log(cloumn.children.length) for(let i=0;i<cloumn.children.length;i++) { console.log(cloumn.children[i].name) console.log(cloumn.children[i].color) } } } }
|
