GridLayout QML Type

提供一种在网格中动态排列项目的方法。更多

Import Statement: import QtQuick.Layouts
Inherits:

Item

属性

详细说明

为了更有效地使用该类型,建议您了解Qt Quick Layouts 模块的一般机制。有关详细信息,请参阅Qt Quick Layouts Overview

如果调整 GridLayout 的大小,布局中的所有项目都将重新排列。这与基于部件的QGridLayout 类似。GridLayout 元素的所有可见子元素都属于该布局。如果你想要一个只有一行或一列的布局,可以使用RowLayoutColumnLayout 。这些提供了更方便的 API,并提高了可读性。

默认情况下,项目将根据flow 属性排列。flow 属性的默认值是GridLayout.LeftToRight

如果指定了columns 属性,在自动定位返回到下一行的开头之前,它将被视为布局所能拥有列数的最大限制。columns 属性仅在flowGridLayout.LeftToRight 时使用。

GridLayout {
    id: grid
    columns: 3

    Text { text: "Three"; font.bold: true; }
    Text { text: "words"; color: "red" }
    Text { text: "in"; font.underline: true }
    Text { text: "a"; font.pixelSize: 20 }
    Text { text: "row"; font.strikeout: true }
}

rows 属性的工作方式类似,但项目是垂直自动定位的。rows 属性仅在flowGridLayout.TopToBottom 时使用。

您可以通过设置Layout.rowLayout.column 属性,指定项目要占用的单元格。您还可以通过设置Layout.rowSpanLayout.columnSpan 属性来指定行跨度或列跨度。

GridLayout 中的项目支持这些附加属性:

在此阅读有关附加属性的更多信息。

另请参阅 RowLayout,ColumnLayout,StackLayout,GridQt Quick 布局概述

属性文档

columnSpacing : real

该属性保存每列之间的间距。默认值为5


columns : int

如果flowGridLayout.LeftToRight ,则该属性为定位项目的列限制。默认值为无限制。


flow : enumeration

该属性用于保存未设置明确单元格位置的项目的流动方向。它与columnsrows 属性一起使用,这两个属性分别指定何时重置流向下一行或下一列。

可能的值有

常量说明
GridLayout.LeftToRight(默认)项目彼此相邻定位,然后换行到下一行。
GridLayout.TopToBottom项目从上到下相邻定位,然后封装到下一列。

另请参阅 rowscolumns


layoutDirection : enumeration [since QtQuick.Layouts 1.1]

该属性表示网格布局的布局方向--它控制项目是从左到右还是从右到左布局。如果指定Qt.RightToLeft ,则左对齐的项目将右对齐,右对齐的项目将左对齐。

可能的值:

常量说明
Qt.LeftToRight(默认)项目从左到右排列。
Qt.RightToLeft项目从右向左排列。

该属性在 QtQuick.Layouts 1.1 中引入。

另请参阅 RowLayout::layoutDirectionColumnLayout::layoutDirection


rowSpacing : real

该属性保留每行之间的间距。默认值为5


rows : int

如果flowGridLayout.TopToBottom ,则该属性为定位项的行数限制。默认值为无限制。


uniformCellHeights : bool [since QtQuick.Layouts 6.6]

如果此属性设置为true ,布局将强制所有单元格具有统一的高度。在此模式下,布局的目标是尊重Layout.minimumHeightLayout.preferredHeightLayout.maximumHeight ,但可能会做出妥协以满足所有项目的要求。

默认值为false

该属性在 QtQuick.Layouts 6.6 中引入。

另请参阅 GridLayout::uniformCellWidths,RowLayout::uniformCellSizes, 和ColumnLayout::uniformCellSizes


uniformCellWidths : bool [since QtQuick.Layouts 6.6]

如果该属性设置为true ,布局将强制所有单元格具有统一的宽度。在此模式下,布局的目标是尊重Layout.minimumWidth,Layout.preferredWidthLayout.maximumWidth ,但可能会做出妥协以满足所有项目的要求。

默认值为false

该属性在 QtQuick.Layouts 6.6 中引入。

另请参阅 GridLayout::uniformCellHeights,RowLayout::uniformCellSizes, 和ColumnLayout::uniformCellSizes


© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.