aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/doc/src/concepts/positioning/layouts.qdoc
blob: 6b4fed79e4d6fcbf095bae80b9a53e541971034c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
\page qtquick-positioning-layouts.html
\title Item Positioners

Positioner items are container items that manage the positions of
items in a declarative user interface. Positioners behave in a similar way to
the \l{Qt Widgets}{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.

\l{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.

\section1 Positioners

A set of standard positioners are provided in the basic set of Qt Quick
graphical types:

\annotatedlist qtquick-positioners

\section2 Column Items

\div {class="float-right"}
\inlineimage qml-column.png
\enddiv

\l Column items are used to vertically arrange items. The following example
uses a Column item to arrange three \l Rectangle items in an area defined
by an outer \l Item. The \l{Column::spacing}{spacing} property is set to
include a small amount of space between the rectangles.

\snippet qml/column/column.qml document

Note that, since Column inherits directly from Item, any background color
must be added to a parent Rectangle, if desired.

\section2 Row Items

\div {class="float-right"}
\inlineimage qml-row.png
\enddiv

\l Row items are used to horizontally arrange items. The following example
uses a Row item to arrange three rounded \l Rectangle items in an area defined
by an outer colored Rectangle. The \l{Row::spacing}{spacing} property is set to
include a small amount of space between the rectangles.

We ensure that the parent Rectangle is large enough so that there is some space
left around the edges of the horizontally centered Row item.

\snippet qml/row.qml document

\section2 Grid Items

\div {class="float-right"}
\inlineimage qml-grid-spacing.png
\enddiv

\l Grid items are used to place items in a grid or table arrangement.
The following example uses a Grid item to place four \l Rectangle items
in a 2-by-2 grid. As with the other positioners, the spacing between items
can be specified using the \l{Grid::spacing}{spacing} property.

\snippet qml/grid-spacing.qml document

There is no difference between horizontal and vertical spacing inserted
between items, so any additional space must be added within the items
themselves.

Any empty cells in the grid must be created by defining placeholder items
at the appropriate places in the Grid definition.

\section2 Flow Items

\div {class="float-right"}
\inlineimage qml-flow-text1.png
\inlineimage qml-flow-text2.png
\enddiv

\l Flow items are used to place items like words on a page, with rows or
columns of non-overlapping items.

Flow items arrange items in a similar way to \l Grid items, with items
arranged in lines along one axis (the minor axis), and lines of items
placed next to each other along another axis (the major axis). The
direction of flow, as well as the spacing between items, are controlled
by the \l{Flow::}{flow} and \l{Flow::}{spacing} properties.

The following example shows a Flow item containing a number of \l Text
child items. These are arranged in a similar way to those shown in the
screenshots.

\snippet qml/flow.qml document

The main differences between the Grid and Flow positioners are that items
inside a Flow will wrap when they run out of space on the minor axis, and
items on one line may not be aligned with items on another line if the
items do not have uniform sizes. As with Grid items, there is no independent
control of spacing between items and between lines of items.

\section1 Other Ways to Position Items

There are several other ways to position items in a user interface. In addition
to the basic technique of specifying their coordinates directly, they can be
positioned relative to other items with \l{anchor-layout}{anchors}, or used
with \l{QML Data Models} such as \l{QML Data Models#Object Model}{Object Model}.
*/