gpt4 book ai didi

Qt5 QML,何时使用 ColumnLayout 与 Column?

转载 作者:行者123 更新时间:2023-12-04 02:11:44 25 4
gpt4 key购买 nike

例如,这有效:

import QtQuick 2.5
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.2

ApplicationWindow
{
visible: true
width: 640
height: 480
title: qsTr("Hello World")

function thingWidth()
{
return width*80/100
}

Column
{
spacing: 10;
anchors.horizontalCenter: parent.horizontalCenter

Thing { color: "red"; width: thingWidth(); }
Thing { color: "yellow"; width: thingWidth(); }
Thing { color: "green"; width: thingWidth(); }
}

}

但是改变 ColumnColumnLayout它没有(调整窗口大小会导致布局出错)。

任何帮助,谢谢。

编辑1:

这里还有 Thing.qml按照要求,
import QtQuick 2.0

Item {
property alias color: rectangle.color
width: 50; height: 50

Rectangle
{
id: rectangle
border.color: "white"
anchors.fill: parent
}
}

看起来我的帖子主要是代码。是的,保姆确实如此!那是因为人们在这里发布代码。

最佳答案

documentationColumn :

Column is a type that positions its child items along a single column. It can be used as a convenient way to vertically position a series of items without using anchors.


此外,它简化了插入、删除等过程中的转换。它还附有 properties到项目,给他们关于他们的位置的概念。
在另一边, thisGridLayout 的文档(请注意, ColumnLayout 是一个便利实用程序,但它只不过是一个具有一列的网格,从它的 documentation 开始)。
它有一组完全不同的属性,以及附加的属性,完全面向项目的排列。
无论如何,我想文档中最有趣的页面是 that一。
我简单地引用它:

Positioner items are container items that manage the positions of items in a declarative user interface. Positioners behave in a similar way to the layout managers used with standard Qt widgets, except that they are also containers in their own right.

Positioners make it easier to work with many items when they need to be arranged in a regular layout.

Qt Quick Layouts can also be used to arrange Qt Quick items in a user interface. They manage both the positions and the sizes of items on a declarative user interface, and are well suited for resizable user interfaces.


请注意, ColumnPositioner ,而 ColumnLayoutLayout .像往常一样,何时使用它们主要取决于您的目标。

关于Qt5 QML,何时使用 ColumnLayout 与 Column?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35560164/

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