QML中Column的使用及示例

来源:互联网 发布:无间道刘建明知乎 编辑:程序博客网 时间:2024/05/18 14:11

其实它和Row是相同的,依旧是添加五个按钮:


import QtQuick 2.3import QtQuick.Window 2.2import QtQuick.Controls 1.4Window {    visible: true    width: 300    height: 300    Rectangle{    anchors.fill: parent    Column{    anchors.left: parent.left    anchors.leftMargin: 4    anchors.bottom: parent.bottom    anchors.bottomMargin: 4    Button{    id:button1    text:qsTr("按钮1")    }    Button{    id:button2    text:qsTr("按钮2")    }    Button{    id:button3    text:qsTr("按钮3")    }    Button{    id:button4    text:qsTr("按钮4")    }    Button{    id:button5    text:qsTr("按钮5")    }    }    }    }

要是非要找点不同,那就是位置了,看效果图:

从图上可以看出,按钮5是在最下面的。

我们的代码想要表达的意思是布局从左下角开始,没错,这里的布局也就从左下角开始了。QT自动为我们进行了优化,使得按钮1在最上面,按钮5在最下面,而且位置非常恰当。

0 0
原创粉丝点击