java gridlayout 权重_QML布局:如何为行或列布局中的项目赋予权重?

我试图通过为每个项目指定一种权重来找出按比例布局项目的方法 . 例如Android的方式layouts .

我试图实现它的方式是这样的:

import QtQuick 2.10

import QtQuick.Controls 2.3

import QtQuick.Layouts 1.3

GridLayout {

columns: 4

width: 640

height: 480

Rectangle {

color: "red"

Layout.fillHeight: true

Layout.fillWidth: true

Layout.columnSpan: 1

}

Rectangle {

color: "#80000000"

Layout.fillHeight: true

Layout.fillWidth: true

Layout.columnSpan: 2

}

Rectangle {

color: "blue"

Layout.fillHeight: true

Layout.fillWidth: true

Layout.columnSpan: 1

}

}

我希望中间矩形的宽度是其他两个矩形的总和,但它们都是相等的宽度 .

在Layout附加属性上使用关系绑定似乎总是导致奇怪的绑定循环 . 我知道我可以使用一行而不是关系绑定,但如果可能的话我更喜欢使用Layouts .

EDIT

这似乎按我想要的方式工作,但我不知道为什么它有效 . 它的行为就像 preferredWidth 值是项目的权重一样 .

import QtQuick 2.10

import QtQuick.Controls 2.3

import QtQuick.Layouts 1.3

RowLayout {

width: 640

height: 480

Rectangle {

color: "red"

Layout.fillHeight: true

Layout.fillWidth: true

Layout.preferredWidth: 1

}

Rectangle {

color: "#80000000"

Layout.fillHeight: true

Layout.fillWidth: true

Layout.preferredWidth: 2

}

Rectangle {

color: "blue"

Layout.fillHeight: true

Layout.fillWidth: true

Layout.preferredWidth: 1

}

}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值