一.ColumnLayout讲解
QML中的ColumnLayout是一种布局元素,用于在垂直列中排列其子元素。它的主要使用下列附加属性:
Layout.minimumWidthLayout.minimumHeight
Layout.preferredWidth
Layout.preferredHeight
Layout.maximumWidth
Layout.maximumHeight
Layout.fillWidth
Layout.fillHeight
Layout.alignment
二.ColumnLayout使用示例:
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Layouts 1.12Window {visible: truewidth: 640height: 480title: qsTr("ColumnLayout Example")ColumnLayout {anchors.fill: parentanchors.margins: 10spacing: 10Rectangle {color: "red"Layout.preferredWidth: 100Layout.preferredHeight: 100}//填充布局区域所在的宽和高Rectangle {color: "green"Layout.fillWidth: true;Layout.fillHeight: true;}Rectangle {color: "blue"Layout.preferredWidth: 100Layout.preferredHeight: 100}}
}
运行结果: