1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
5\page qtquick-positioning-topic.html
6\title Important Concepts In Qt Quick - Positioning
7\brief Overview of positioning concepts
9Visual items in QML can be positioned in a variety of ways. The most important
10positioning-related concept is that of anchoring, a form of relative
11positioning where items can be anchored (or attached) to each other at certain
12boundaries. Other positioning concepts include absolute positioning,
13positioning with coordinate bindings, positioners, and layouts.
16\section1 Manual Positioning
18Items can be positioned manually. If the user-interface is going to be
19static, manual positioning provides the most efficient form of positioning.
21In any user-interface, the visual types exist at a particular location in
22the screen coordinates at any instant in time. While fluidly animated and
23dynamic user-interfaces are a major focus of Qt Quick, statically-positioned
24user interfaces are still a viable option. What's more, if the position of
25those types does not change, it can often be more performant to specify
26the position manually than to use the more dynamic positioning methods
27documented in proceeding sections.
29In Qt Quick, every visual object is positioned within the
30\l{Concepts - Visual Coordinates in Qt Quick}{coordinate system}
31provided by the Qt Quick visual canvas. As described in that document, the
32x and y coordinates of a visual object are relative to those of its visual
33parent, with the top-left corner having the coordinate (0, 0).
35Thus, the following example will display two rectangles positioned manually:
69 \image manual-layout.png
72\section1 Positioning With Bindings
74Items may also be positioned by assigning binding expressions to the properties
75associated with their location in the visual canvas. This type of positioning
76is the most highly dynamic, however some performance cost is associated with
77positioning items in this manner.
79The position and dimensions of a visual object can also be set through property
80bindings. This has the advantage that the values will automatically be updated
81as the dependencies of the bindings change. For example, the width of one
82Rectangle might depend on the width of the Rectangle next to it.
84While bindings provide a very flexible and intuitive way of creating dynamic
85layouts, it should be noted that there is some performance cost associated with
86them, and where possible, pristine Anchor layouts should be preferred.
91Anchors allow an item to be placed either adjacent to or inside of another,
92by attaching one or more of the item's anchor-points (boundaries) to an
93anchor-point of the other. These anchors will remain even if the dimensions
94or location of one of the items changes, allowing for highly dynamic
97A visual object can be thought of as having various anchor-points (or more
98correctly, anchor-lines). Other items can be anchored to those points, which
99means that as any object changes, the other objects which are anchored to it
100will adjust automatically to maintain the anchoring.
102Qt Quick provides anchors as a top-level concept. See the documentation about
103\l{qtquick-positioning-anchors.html}{positioning with anchors}
104for in-depth information on the topic.
106It is important to note that anchor-based layouts are generally far more
107performant than binding-based layouts, if pristine. A "pristine" anchor layout
108is one which uses only anchors (with object nesting) to determine the
109positioning, whereas a "contaminated" anchor layout is one which uses both
110anchoring and bindings (either on position-related [x,y] properties or on
111dimension-related [width,height] properties) to determine the position.
115Qt Quick also provides some built-in positioner items. For many use cases, the best
116positioner to use is a simple grid, row, or column, and Qt Quick provides items which
117will position children in these formations in the most efficient manner possible.
118See the documentation on \l{qtquick-positioning-layouts.html}{item positioners types}
119for more information about utilizing pre-defined positioners.
123From Qt 5.1, the module \l {Qt Quick Layouts} can also be used to arrange Qt Quick
124items in a user interface. Unlike positioners, the types in Qt Quick Layouts manage
125both the positions and sizes of items in a declarative interface. They are well
126suited for resizable user interfaces.
128\section1 Right-To-Left Support
130The directionality of the written form of a language often has a great impact
131on how the visual types of a user-interface should be positioned. Qt Quick
132supports right-to-left positioning of types through the predefined-layouts
133as well as right-to-left text layouts.
135Please see the documentation about
136\l{qtquick-positioning-righttoleft.html}
137{right-to-left support in Qt Quick} for in-depth information on the topic.