qt - QML ColumnLayout 不尊重 minimumHeight
问题描述
我总是对 QML 的布局管理有问题。因此,我创建了一个非常简单的 QML App 来检查 ColumnLayout。如果我水平缩小窗口,当达到 100 时它将停止在 minimumWitdh 处。但是如果我垂直缩小窗口,我可以缩小窗口,这样两个矩形都会消失。
出了什么问题?为什么不尊重 minimumHeight ?
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Layouts 1.15
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
ColumnLayout {
Rectangle {
color: "red"
Layout.minimumWidth: 100
Layout.minimumHeight: 100
}
Rectangle {
color: "blue"
Layout.minimumWidth: 100
Layout.minimumHeight: 100
}
}
}
解决方案
福尔比斯可能是对的。但我找到了另一个解决方案。似乎 minimumWidth 和 minimumHeight 将计算 ColumnLayout 的隐式宽度和隐式高度。因此,这又可以用作窗口的 minimumWidth 和 minimumHeight,如下所示:
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
minimumHeight: col.implicitHeight
minimumWidth: col.implicitWidth
ColumnLayout {
id: col
Rectangle {
color: "red"
Layout.minimumWidth: 100
Layout.minimumHeight: 100
}
Rectangle {
color: "blue"
Layout.minimumWidth: 100
Layout.minimumHeight: 100
}
}
}
当您来自 XAML 世界时,这很奇怪。
推荐阅读
- java - Camel CXF - 操作输出解组错误
- javascript - 倒数计时器多项
- java - How to parse 2018-06-19T05:50:31.000+0000 date string to Date
- python - Selenium ConnectionAbortedError
- azure - 什么在请求我的 azure servicebus 队列
- optimization - Julia 的 Optim.jl 包无法执行盒装优化
- php - 如何在 Laravel 中检查多个 url 的状态
- jquery - 使用 jQuery 重新组织项目
- r - mclapply 与 lme4 和长向量
- drupal - 5 次尝试失败后 Drupal 需要多长时间才能解除对用户的阻止?