qml 之item学习

来源:互联网 发布:淘宝图片怎么拍 编辑:程序博客网 时间:2024/06/06 11:29

qml之动态创建与销毁

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            }        }    }

运行结果:
![这里写图片描述](http://img.blog.csdn.net/20170405104756522?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYmFpZHVfMTUxNzM5NTk=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast

0 0