gpt4 book ai didi

qml - QML 布局中元素的自动换行

转载 作者:行者123 更新时间:2023-12-02 17:26:14 24 4
gpt4 key购买 nike

如果下一个元素的宽度超过指定布局的宽度,是否有 QML 布局或某些配置会自动将 QML 项目包装到下一行?

当我使用 QML GridLayout ,项目刚好离开窗口的边缘并被剪裁:

GridLayout {
id: header_focused_container;
width: parent.width;
anchors.margins: 20;
Text {
text: "header_focused_container.width=" +
header_focused_container.width +
" and my width is =" + width
}
Rectangle { height:20; width:250; color: "red" }
Rectangle { height:20; width:250; color: "blue" }
Rectangle { height:20; width:250; color: "green" }
}

Gridlayout efforts[1]

当我查看标记为 "Scalability" 的 Qt 文档页面时我看到非常手动的缩放正在进行。基本上,他们建议我需要计算所需的列。

是否有某种布局类型或配置可以自动换行项目?

最佳答案

您可以使用 Flow :

import QtQuick 2.5
import QtQuick.Window 2.0

Window {
visible: true
width: 400
height: 200

Flow {
id: header_focused_container
anchors.fill: parent

Text {
text: "blah"
}
Rectangle { height:20; width:250; color: "red" }
Rectangle { height:20; width:250; color: "blue" }
Rectangle { height:20; width:250; color: "green" }
}
}

关于qml - QML 布局中元素的自动换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38531882/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com