gridlayout用法 java_如何使用比例大小的项目创建QML GridLayout?

我一直在尝试使用跨越可变数量的行和列的项创建QML布局 . 因此,例如,一个跨越两行四列的矩形,其中一个跨越一行和两列,另一个跨越三行和五列 . 创建此的一般尝试如下:

import QtQuick 2.5

import QtQuick.Layouts 1.2

import QtQuick.Controls 1.4

ApplicationWindow {

visible: true

width: 640

height: 480

title: qsTr("Hello World")

GridLayout {

anchors.fill: parent

columns: 5

rows: 2

Rectangle {

Layout.column: 0

Layout.columnSpan: 4

Layout.row: 0

Layout.rowSpan: 2

Layout.fillHeight: true

Layout.fillWidth: true

color: "red"

}

Rectangle {

Layout.column: 4

Layout.columnSpan: 1

Layout.row: 0

Layout.rowSpan: 2

Layout.fillHeight: true

Layout.fillWidth: true

color: "green"

}

Rectangle {

Layout.column: 0

Layout.columnSpan: 5

Layout.row: 2

Layout.rowSpan: 3

Layout.fillHeight: true

Layout.fillWidth: true

color: "blue"

}

}

}

结果如下:

afdeaac8-3c01-4b2e-88ea-8f776a5d700f.png

如您所见,Layout.rowSpan和Layout.columnspan似乎不起作用 . 相反,前两行似乎占1:1而不是4:1,而顶部与底部相比是1:1而不是2:3 . 我怀疑这与Layout.fillHeight和Layout.fillWidth有关 . The documentation州:

如果此属性为true,则项目将尽可能宽,同时遵守给定的约束 .

但我不确定在这种情况下“给定的约束”是什么 . 我原本希望它包括行和列 Span ,但似乎没有 .

我可能直接计算项目的宽度和高度(或者可能是Layout.preferredWidth和Layout.preferredHeight),但这似乎使Layout.rowSpan和Layout.columnSpan完全是多余的 . 有没有办法根据网格行和列自动计算高度?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值