Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
layouts.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2017 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page qtquick-positioning-layouts.html
6
\title Item Positioners
7
8
Positioner items are container items that manage the positions of
9
items in a declarative user interface. Positioners behave in a similar way to
10
the \l{Qt Widgets}{layout managers} used with standard Qt widgets,
11
except that they are also containers in their own right.
12
13
Positioners make it easier to work with many items when they need
14
to be arranged in a regular layout.
15
16
\l{Qt Quick Layouts} can also be used to arrange Qt Quick items in a user interface.
17
They manage both the positions and the sizes of items on a declarative user interface,
18
and are well suited for resizable user interfaces.
19
20
\section1 Positioners
21
22
A set of standard positioners are provided in the basic set of Qt Quick
23
graphical types:
24
25
\annotatedlist qtquick-positioners
26
27
\section2 Column Items
28
29
\div {class="float-right"}
30
\inlineimage qml-column.png
31
{Three rectangles stacked vertically labeled Books, Music, Movies}
32
\enddiv
33
34
\l Column items are used to vertically arrange items. The following example
35
uses a Column item to arrange three \l Rectangle items in an area defined
36
by an outer \l Item. The \l{Column::spacing}{spacing} property is set to
37
include a small amount of space between the rectangles.
38
39
\snippet qml/column/column.qml document
40
41
Note that, since Column inherits directly from Item, any background color
42
must be added to a parent Rectangle, if desired.
43
44
\section2 Row Items
45
46
\div {class="float-right"}
47
\inlineimage qml-row.png
48
{Three rounded rectangles arranged horizontally}
49
\enddiv
50
51
\l Row items are used to horizontally arrange items. The following example
52
uses a Row item to arrange three rounded \l Rectangle items in an area defined
53
by an outer colored Rectangle. The \l{Row::spacing}{spacing} property is set to
54
include a small amount of space between the rectangles.
55
56
We ensure that the parent Rectangle is large enough so that there is some space
57
left around the edges of the horizontally centered Row item.
58
59
\snippet qml/row.qml document
60
61
\section2 Grid Items
62
63
\div {class="float-right"}
64
\inlineimage qml-grid-spacing.png
65
{Four colored rectangles in a 2-by-2 grid with spacing}
66
\enddiv
67
68
\l Grid items are used to place items in a grid or table arrangement.
69
The following example uses a Grid item to place four \l Rectangle items
70
in a 2-by-2 grid. As with the other positioners, the spacing between items
71
can be specified using the \l{Grid::spacing}{spacing} property.
72
73
\snippet qml/grid-spacing.qml document
74
75
There is no difference between horizontal and vertical spacing inserted
76
between items, so any additional space must be added within the items
77
themselves.
78
79
Any empty cells in the grid must be created by defining placeholder items
80
at the appropriate places in the Grid definition.
81
82
\section2 Flow Items
83
84
\div {class="float-right"}
85
\inlineimage qml-flow-text1.png
86
{Text items wrapped in a narrow Flow container}
87
\inlineimage qml-flow-text2.png
88
{Text items wrapped in a wider Flow container}
89
\enddiv
90
91
\l Flow items are used to place items like words on a page, with rows or
92
columns of non-overlapping items.
93
94
Flow items arrange items in a similar way to \l Grid items, with items
95
arranged in lines along one axis (the minor axis), and lines of items
96
placed next to each other along another axis (the major axis). The
97
direction of flow, as well as the spacing between items, are controlled
98
by the \l{Flow::}{flow} and \l{Flow::}{spacing} properties.
99
100
The following example shows a Flow item containing a number of \l Text
101
child items. These are arranged in a similar way to those shown in the
102
screenshots.
103
104
\snippet qml/flow.qml document
105
106
The main differences between the Grid and Flow positioners are that items
107
inside a Flow will wrap when they run out of space on the minor axis, and
108
items on one line may not be aligned with items on another line if the
109
items do not have uniform sizes. As with Grid items, there is no independent
110
control of spacing between items and between lines of items.
111
112
\section1 Other Ways to Position Items
113
114
There are several other ways to position items in a user interface. In addition
115
to the basic technique of specifying their coordinates directly, they can be
116
positioned relative to other items with \l{anchor-layout}{anchors}, or used
117
with \l{QML Data Models} such as \l{QML Data Models#Object Model}{Object Model}.
118
*/
qtdeclarative
src
quick
doc
src
concepts
positioning
layouts.qdoc
Generated on
for Qt by
1.16.1