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) 2016 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
/*!
4
\page qtquick-usecase-layouts.html
5
\title Positioners and layouts
6
\keyword Use Case - Positioners and Layouts In QML
7
\brief Example of how to create layouts for visual components in a QML application
8
\ingroup explanations-programminglanguages
9
10
There are several ways to position items in QML.
11
12
Below is a brief overview. For more details, see \l {Important Concepts In Qt Quick - Positioning}.
13
14
\section1 Manual Positioning
15
16
Items can be placed at specific x,y coordinates on the screen by setting their x,y properties. This will
17
setup their position relative to the top left corner of their parent, according to the
18
\l {Concepts - Visual Coordinates in Qt Quick}{visual coordinate system} rules.
19
20
Combined with using \l{Property Binding}{bindings} instead of constant values for these properties, relative positioning is also easily
21
accomplished by setting the x and y coordinates to the appropriate bindings.
22
23
\snippet qmlapp/usecases/layouts.qml import
24
\snippet qmlapp/usecases/layouts.qml direct
25
26
\image qmlapp/qml-uses-layouts-direct.png
27
28
29
\section1 Anchors
30
31
The \c Item type provides the abilitiy to anchor to other \l Item types. There
32
are seven anchor lines for each item: \e left, \e right, \e{vertical center},
33
\e top, \e bottom, \e baseline and \e{horizontal center}. The three vertical
34
anchor lines can be anchored to any of the three vertical anchor lines of
35
another item, and the four horizontal anchor lines can be anchored to the
36
horizontal anchor lines of another item.
37
38
For full details, see \l {Positioning with Anchors} and the documentation of the \l{Item::anchors.top}{anchors property}.
39
40
\snippet qmlapp/usecases/layouts.qml import
41
\snippet qmlapp/usecases/layouts.qml anchors
42
43
\image qmlapp/qml-uses-layouts-anchors.png
44
45
46
\section1 Positioners
47
48
For the common case of wanting to \e position a set of types in a regular pattern, Qt Quick provides some positioner
49
types. Items placed in a positioner are automatically positioned in some way; for example, a \l [QML] Row positions items to be
50
horizontally adjacent (forming a row).
51
52
For full details see \l {Item Positioners}.
53
54
\snippet qmlapp/usecases/layouts.qml import
55
\snippet qmlapp/usecases/layouts.qml positioners
56
57
\image qmlapp/qml-uses-layouts-positioners.png
58
59
\section1 Layout Types
60
61
\e{Layout types} function in a similar way as positioners but allow further refinement or
62
restrictions to the layout. Specifically, the layout types allow you to:
63
64
\list
65
\li set the alignment of text and other items
66
\li resize and fill the allotted application areas automatically
67
\li set size constraints such as minimum or maximum dimensions
68
\li set the spacing between items within the layout
69
\endlist
70
71
\qml
72
GroupBox {
73
id: gridBox
74
title: "Grid layout"
75
Layout.fillWidth: true
76
77
GridLayout {
78
id: gridLayout
79
rows: 3
80
flow: GridLayout.TopToBottom
81
anchors.fill: parent
82
Label { text: "Line 1" }
83
Label { text: "Line 2" }
84
Label { text: "Line 3" }
85
86
TextField { }
87
TextField { }
88
TextField { }
89
90
TextArea {
91
text: "This widget spans over three rows in the GridLayout.\n"
92
+ "All items in the GridLayout are implicitly positioned from top to bottom."
93
Layout.rowSpan: 3
94
Layout.fillHeight: true
95
Layout.fillWidth: true
96
}
97
}
98
}
99
\endqml
100
The snippet above comes from the \l{Qt Quick Layouts - Basic Example}{Basic Layouts} example. The
101
snippet shows the simplicity of adding various fields and items in a layout. The \l [QML] {GridLayout} can
102
be resized and its format is customizable through various properties.
103
104
For more information about the layout types, visit:
105
\list
106
\li \l{Qt Quick Layouts Overview}
107
\li \l{Qt Quick Layouts - Basic Example}{Basic Layouts} example
108
\endlist
109
110
\note \l{Qt Quick Layouts} was introduced in Qt 5.1 and requires \l{Qt Quick} 2.1.
111
112
*/
qtdeclarative
src
quick
doc
src
getting-started
layouts.qdoc
Generated on
for Qt by
1.14.0