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
8Positioner items are container items that manage the positions of
9items in a declarative user interface. Positioners behave in a similar way to
10the \l{Qt Widgets}{layout managers} used with standard Qt widgets,
11except that they are also containers in their own right.
12
13Positioners make it easier to work with many items when they need
14to 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.
17They manage both the positions and the sizes of items on a declarative user interface,
18and are well suited for resizable user interfaces.
19
20\section1 Positioners
21
22A set of standard positioners are provided in the basic set of Qt Quick
23graphical 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
35uses a Column item to arrange three \l Rectangle items in an area defined
36by an outer \l Item. The \l{Column::spacing}{spacing} property is set to
37include a small amount of space between the rectangles.
38
39\snippet qml/column/column.qml document
40
41Note that, since Column inherits directly from Item, any background color
42must 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
52uses a Row item to arrange three rounded \l Rectangle items in an area defined
53by an outer colored Rectangle. The \l{Row::spacing}{spacing} property is set to
54include a small amount of space between the rectangles.
55
56We ensure that the parent Rectangle is large enough so that there is some space
57left 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.
69The following example uses a Grid item to place four \l Rectangle items
70in a 2-by-2 grid. As with the other positioners, the spacing between items
71can be specified using the \l{Grid::spacing}{spacing} property.
72
73\snippet qml/grid-spacing.qml document
74
75There is no difference between horizontal and vertical spacing inserted
76between items, so any additional space must be added within the items
77themselves.
78
79Any empty cells in the grid must be created by defining placeholder items
80at 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
92columns of non-overlapping items.
93
94Flow items arrange items in a similar way to \l Grid items, with items
95arranged in lines along one axis (the minor axis), and lines of items
96placed next to each other along another axis (the major axis). The
97direction of flow, as well as the spacing between items, are controlled
98by the \l{Flow::}{flow} and \l{Flow::}{spacing} properties.
99
100The following example shows a Flow item containing a number of \l Text
101child items. These are arranged in a similar way to those shown in the
102screenshots.
103
104\snippet qml/flow.qml document
105
106The main differences between the Grid and Flow positioners are that items
107inside a Flow will wrap when they run out of space on the minor axis, and
108items on one line may not be aligned with items on another line if the
109items do not have uniform sizes. As with Grid items, there is no independent
110control of spacing between items and between lines of items.
111
112\section1 Other Ways to Position Items
113
114There are several other ways to position items in a user interface. In addition
115to the basic technique of specifying their coordinates directly, they can be
116positioned relative to other items with \l{anchor-layout}{anchors}, or used
117with \l{QML Data Models} such as \l{QML Data Models#Object Model}{Object Model}.
118*/