qml 之item学习
Item是所有基本组件的基类,本篇主要介绍Item一些基本属性,及Item位置控制。
//item:基本的控件都继承自Item,例如Rectangle、Flickable等等
Item{
//相当于实例化的类对象
id:item
//visible:控制tem的显示隐藏
visible: true
//width: height 控制item的大小
width:300
height:200
//opacity item的透明度
opacity: 1
//anchors.centerIn:控制item的位置(居中)
anchors.centerIn: parent
Rectangle{
id:item1
width:150
height:100
//item1的颜色
color:"#000000"
Text{
id:textValue
//color:设置文本颜色
color:"green"
anchors.fill: parent
text:qsTr("learn qml...----/////省略")
//font.pixelSize:文本大小
font.pixelSize: 14
//elide:富文本缩略格式
elide: Text.ElideRight
}
}
Rectangle{
id:item2
width:150
height:100
color:"blue"
//x y:设置item2相对于父组件(item)的位置
x:150
y:0
}
Rectangle{
id:item3
width:150
height:100
color:"red"
x:0
y:100
}
Rectangle{
id:item4
width:150
height:100
color:"#ffffff"
anchors{
top:item1.bottom
topMargin: 0
left:item1.right
leftMargin: 0
}
}
}