QML 布局管理器之ColumnLayout

本文详细介绍了QML中的ColumnLayout布局元素,重点讲解了其主要属性如minimumWidth、fillWidth等,并通过示例展示了如何在垂直列中管理和控制子元素的尺寸和填充效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一.ColumnLayout讲解

QML中的ColumnLayout是一种布局元素,用于在垂直列中排列其子元素。它的主要使用下列附加属性:
Layout.minimumWidth

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

运行结果:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值