GridLayout QML Type
提供一种在网格中动态排列项目的方法。更多
Import Statement: | import QtQuick.Layouts |
Inherits: |
属性
- columnSpacing : real
- columns : int
- flow : enumeration
- layoutDirection : enumeration
(since QtQuick.Layouts 1.1)
- rowSpacing : real
- rows : int
- uniformCellHeights : bool
(since QtQuick.Layouts 6.6)
- uniformCellWidths : bool
(since QtQuick.Layouts 6.6)
详细说明
为了更有效地使用该类型,建议您了解Qt Quick Layouts 模块的一般机制。有关详细信息,请参阅Qt Quick Layouts Overview。
如果调整 GridLayout 的大小,布局中的所有项目都将重新排列。这与基于部件的QGridLayout 类似。GridLayout 元素的所有可见子元素都属于该布局。如果你想要一个只有一行或一列的布局,可以使用RowLayout 或ColumnLayout 。这些提供了更方便的 API,并提高了可读性。
默认情况下,项目将根据flow 属性排列。flow 属性的默认值是GridLayout.LeftToRight
。
如果指定了columns 属性,在自动定位返回到下一行的开头之前,它将被视为布局所能拥有列数的最大限制。columns 属性仅在flow 为GridLayout.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 属性仅在flow 为GridLayout.TopToBottom
时使用。
您可以通过设置Layout.row 和Layout.column 属性,指定项目要占用的单元格。您还可以通过设置Layout.rowSpan 或Layout.columnSpan 属性来指定行跨度或列跨度。
GridLayout 中的项目支持这些附加属性:
- Layout.row
- Layout.column
- Layout.rowSpan
- Layout.columnSpan
- Layout.minimumWidth
- Layout.minimumHeight
- Layout.preferredWidth
- Layout.preferredHeight
- Layout.maximumWidth
- Layout.maximumHeight
- Layout.fillWidth
- Layout.fillHeight
- Layout.alignment
- Layout.margins
- Layout.leftMargin
- Layout.rightMargin
- Layout.topMargin
- Layout.bottomMargin
- Layout.horizontalStretchFactor
- Layout.verticalStretchFactor
在此阅读有关附加属性的更多信息。
另请参阅 RowLayout,ColumnLayout,StackLayout,Grid 和Qt Quick 布局概述。
属性文档
columnSpacing : real |
该属性保存每列之间的间距。默认值为5
。
flow : enumeration |
layoutDirection : enumeration |
该属性表示网格布局的布局方向--它控制项目是从左到右还是从右到左布局。如果指定Qt.RightToLeft
,则左对齐的项目将右对齐,右对齐的项目将左对齐。
可能的值:
常量 | 说明 |
---|---|
Qt.LeftToRight | (默认)项目从左到右排列。 |
Qt.RightToLeft | 项目从右向左排列。 |
该属性在 QtQuick.Layouts 1.1 中引入。
另请参阅 RowLayout::layoutDirection 和ColumnLayout::layoutDirection 。
rowSpacing : real |
该属性保留每行之间的间距。默认值为5
。
uniformCellHeights : bool |
如果此属性设置为true
,布局将强制所有单元格具有统一的高度。在此模式下,布局的目标是尊重Layout.minimumHeight 、Layout.preferredHeight 和Layout.maximumHeight ,但可能会做出妥协以满足所有项目的要求。
默认值为false
。
该属性在 QtQuick.Layouts 6.6 中引入。
另请参阅 GridLayout::uniformCellWidths,RowLayout::uniformCellSizes, 和ColumnLayout::uniformCellSizes 。
uniformCellWidths : bool |
如果该属性设置为true
,布局将强制所有单元格具有统一的宽度。在此模式下,布局的目标是尊重Layout.minimumWidth,Layout.preferredWidth 和Layout.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.