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
topic.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-topic.html
6
\title Important Concepts In Qt Quick - Positioning
7
\brief Overview of positioning concepts
8
\ingroup explanations-programminglanguages
9
10
Visual items in QML can be positioned in a variety of ways. The most important
11
positioning-related concept is that of anchoring, a form of relative
12
positioning where items can be anchored (or attached) to each other at certain
13
boundaries. Other positioning concepts include absolute positioning,
14
positioning with coordinate bindings, positioners, and layouts.
15
16
17
\section1 Manual Positioning
18
19
Items can be positioned manually. If the user-interface is going to be
20
static, manual positioning provides the most efficient form of positioning.
21
22
In any user-interface, the visual types exist at a particular location in
23
the screen coordinates at any instant in time. While fluidly animated and
24
dynamic user-interfaces are a major focus of Qt Quick, statically-positioned
25
user interfaces are still a viable option. What's more, if the position of
26
those types does not change, it can often be more performant to specify
27
the position manually than to use the more dynamic positioning methods
28
documented in proceeding sections.
29
30
In Qt Quick, every visual object is positioned within the
31
\l{Concepts - Visual Coordinates in Qt Quick}{coordinate system}
32
provided by the Qt Quick visual canvas. As described in that document, the
33
x and y coordinates of a visual object are relative to those of its visual
34
parent, with the top-left corner having the coordinate (0, 0).
35
36
Thus, the following example will display two rectangles positioned manually:
37
38
\table
39
\header
40
\li Example Code
41
\li Resultant Layout
42
43
\row
44
\li
45
\qml
46
import QtQuick 2.0
47
48
Item {
49
width: 200
50
height: 200
51
52
Rectangle {
53
x: 50
54
y: 50
55
width: 100
56
height: 100
57
color: "green"
58
}
59
60
Rectangle {
61
x: 100
62
y: 100
63
width: 50
64
height: 50
65
color: "yellow"
66
}
67
}
68
\endqml
69
\li
70
\image manual-layout.png
71
\endtable
72
73
\section1 Positioning With Bindings
74
75
Items may also be positioned by assigning binding expressions to the properties
76
associated with their location in the visual canvas. This type of positioning
77
is the most highly dynamic, however some performance cost is associated with
78
positioning items in this manner.
79
80
The position and dimensions of a visual object can also be set through property
81
bindings. This has the advantage that the values will automatically be updated
82
as the dependencies of the bindings change. For example, the width of one
83
Rectangle might depend on the width of the Rectangle next to it.
84
85
While bindings provide a very flexible and intuitive way of creating dynamic
86
layouts, it should be noted that there is some performance cost associated with
87
them, and where possible, pristine Anchor layouts should be preferred.
88
89
90
\section1 Anchors
91
92
Anchors allow an item to be placed either adjacent to or inside of another,
93
by attaching one or more of the item's anchor-points (boundaries) to an
94
anchor-point of the other. These anchors will remain even if the dimensions
95
or location of one of the items changes, allowing for highly dynamic
96
user-interfaces.
97
98
A visual object can be thought of as having various anchor-points (or more
99
correctly, anchor-lines). Other items can be anchored to those points, which
100
means that as any object changes, the other objects which are anchored to it
101
will adjust automatically to maintain the anchoring.
102
103
Qt Quick provides anchors as a top-level concept. See the documentation about
104
\l{qtquick-positioning-anchors.html}{positioning with anchors}
105
for in-depth information on the topic.
106
107
It is important to note that anchor-based layouts are generally far more
108
performant than binding-based layouts, if pristine. A "pristine" anchor layout
109
is one which uses only anchors (with object nesting) to determine the
110
positioning, whereas a "contaminated" anchor layout is one which uses both
111
anchoring and bindings (either on position-related [x,y] properties or on
112
dimension-related [width,height] properties) to determine the position.
113
114
\section1 Positioners
115
116
Qt Quick also provides some built-in positioner items. For many use cases, the best
117
positioner to use is a simple grid, row, or column, and Qt Quick provides items which
118
will position children in these formations in the most efficient manner possible.
119
See the documentation on \l{qtquick-positioning-layouts.html}{item positioners types}
120
for more information about utilizing pre-defined positioners.
121
122
\section1 Layouts
123
124
From Qt 5.1, the module \l {Qt Quick Layouts} can also be used to arrange Qt Quick
125
items in a user interface. Unlike positioners, the types in Qt Quick Layouts manage
126
both the positions and sizes of items in a declarative interface. They are well
127
suited for resizable user interfaces.
128
129
\section1 Right-To-Left Support
130
131
The directionality of the written form of a language often has a great impact
132
on how the visual types of a user-interface should be positioned. Qt Quick
133
supports right-to-left positioning of types through the predefined-layouts
134
as well as right-to-left text layouts.
135
136
Please see the documentation about
137
\l{qtquick-positioning-righttoleft.html}
138
{right-to-left support in Qt Quick} for in-depth information on the topic.
139
140
141
*/
qtdeclarative
src
quick
doc
src
concepts
positioning
topic.qdoc
Generated on
for Qt by
1.14.0