一.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.12
Window {
visible: true
width: 640
height: 480
title: qsTr("ColumnLayout Example")
ColumnLayout {
anchors.fill: parent
anchors.margins: 10
spacing: 10
Rectangle {
color: "red"
Layout.preferredWidth: 100
Layout.preferredHeight: 100
}
//填充布局区域所在的宽和高
Rectangle {
color: "green"
Layout.fillWidth: true;
Layout.fillHeight: true;
}
Rectangle {
color: "blue"
Layout.preferredWidth: 100
Layout.preferredHeight: 100
}
}
}
运行结果: