source: trunk/doc/src/declarative/positioners.qdoc@ 1147

Last change on this file since 1147 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 7.2 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:FDL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in a
14** written agreement between you and Nokia.
15**
16** GNU Free Documentation License
17** Alternatively, this file may be used under the terms of the GNU Free
18** Documentation License version 1.3 as published by the Free Software
19** Foundation and appearing in the file included in the packaging of this
20** file.
21**
22** If you have questions regarding the use of this file, please contact
23** Nokia at qt-info@nokia.com.
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29\page qml-positioners.html
30\title Using QML Positioner and Repeater Items
31
32\section1 Introduction
33
34Positioner items are container items that manage the positions and sizes of
35items in a declarative user interface. Positioners behave in a similar way to
36the \l{Widgets and Layouts}{layout managers} used with standard Qt widgets,
37except that they are also containers in their own right.
38
39Positioners and repeaters make it easier to work with many items when they need
40to be arranged in a regular layout.
41
42\section1 Positioners
43
44A set of standard positioners are provided in the basic set of Qt Quick
45graphical elements:
46
47\list
48\o \l{#Column}{Column} arranges its children in a column
49\o \l{#Row}{Row} arranges its children in a row
50\o \l{#Grid}{Grid} arranges its children in a grid
51\o \l{#Flow}{Flow} arranges its children like words on a page
52\endlist
53
54\section2 Column
55
56\beginfloatright
57\image qml-column.png
58\endfloat
59
60\l Column items are used to vertically arrange items. The following example
61uses a Column item to arrange three \l Rectangle items in an area defined
62by an outer \l Item. The \l{Column::spacing}{spacing} property is set to
63include a small amount of space between the rectangles.
64
65\clearfloat
66\snippet doc/src/snippets/declarative/column/column.qml document
67
68Note that, since Column inherits directly from Item, any background color
69must be added to a parent Rectangle, if desired.
70
71\section2 Row
72
73\beginfloatright
74\image qml-row.png
75\endfloat
76
77\l Row items are used to horizontally arrange items. The following example
78uses a Row item to arrange three rounded \l Rectangle items in an area defined
79by an outer colored Rectangle. The \l{Row::spacing}{spacing} property is set to
80include a small amount of space between the rectangles.
81
82We ensure that the parent Rectangle is large enough so that there is some space
83left around the edges of the horizontally centered Row item.
84
85\clearfloat
86\snippet doc/src/snippets/declarative/row.qml document
87
88\section2 Grid
89
90\beginfloatright
91\image qml-grid-spacing.png
92\endfloat
93
94\l Grid items are used to place items in a grid or table arrangement.
95The following example uses a Grid item to place four \l Rectangle items
96in a 2-by-2 grid. As with the other positioners, the spacing between items
97can be specified using the \l{Grid::spacing}{spacing} property.
98
99\clearfloat
100\snippet doc/src/snippets/declarative/grid/grid-spacing.qml document
101
102There is no difference between horizontal and vertical spacing inserted
103between items, so any additional space must be added within the items
104themselves.
105
106Any empty cells in the grid must be created by defining placeholder items
107at the appropriate places in the Grid definition.
108
109\section2 Flow
110
111\beginfloatright
112\image qml-flow-text1.png
113\image qml-flow-text2.png
114\endfloat
115
116\l Flow items are used to place items like words on a page, with rows or
117columns of non-overlapping items.
118
119Flow items arrange items in a similar way to \l Grid items, with items
120arranged in lines along one axis (the minor axis), and lines of items
121placed next to each other along another axis (the major axis). The
122direction of flow, as well as the spacing between items, are controlled
123by the \l{Flow::}{flow} and \l{Flow::}{spacing} properties.
124
125The following example shows a Flow item containing a number of \l Text
126child items. These are arranged in a similar way to those shown in the
127screenshots.
128
129\clearfloat
130\snippet doc/src/snippets/declarative/flow.qml document
131
132The main differences between the Grid and Flow positioners are that items
133inside a Flow will wrap when they run out of space on the minor axis, and
134items on one line may not be aligned with items on another line if the
135items do not have uniform sizes. As with Grid items, there is no independent
136control of spacing between items and between lines of items.
137
138\section1 Repeaters
139
140\beginfloatright
141\image qml-repeater-grid-index.png
142\endfloat
143
144Repeaters create items from a template for use with positioners, using data
145from a model. Combining repeaters and positioners is an easy way to lay out
146lots of items. A \l Repeater item is placed inside a positioner, and generates
147items that the enclosing positioner arranges.
148
149Each Repeater creates a number of items by combining each element of data
150from a model, specified using the \l{Repeater::model}{model} property, with
151the template item, defined as a child item within the Repeater.
152The total number of items is determined by the amount of data in the model.
153
154The following example shows a repeater used with a \l{#Grid}{Grid} item to
155arrange a set of Rectangle items. The Repeater item creates a series of 24
156rectangles for the Grid item to position in a 5 by 5 arrangement.
157
158\clearfloat
159\snippet doc/src/snippets/declarative/repeaters/repeater-grid-index.qml document
160
161The number of items created by a Repeater is held by its \l{Repeater::}{count}
162property. It is not possible to set this property to determine the number of
163items to be created. Instead, as in the above example, we use an integer as
164the model. This is explained in the \l{QML Data Models#An Integer}{QML Data Models}
165document.
166
167It is also possible to use a delegate as the template for the items created
168by a Repeater. This is specified using the \l{Repeater::}{delegate} property.
169
170\section1 Using Transitions
171
172Transitions can be used to animate items that are added to, moved within,
173or removed from a positioner.
174
175Transitions for adding items apply to items that are created as part of a
176positioner, as well as those that are reparented to become children of a
177positioner.
178Transitions for removing items apply to items within a positioner that are
179deleted, as well as those that are removed from a positioner and given new
180parents in a document.
181
182Additionally, changing the opacity of items to zero will cause them to
183disappear using the remove transition, and making the opacity non-zero will
184cause them to appear using the add transition.
185
186\section1 Other Ways to Position Items
187
188There are several other ways to position items in a user interface. In addition
189to the basic technique of specifying their coordinates directly, they can be
190positioned relative to other items with \l{anchor-layout}{anchors}, or used
191with \l{QML Data Models} such as
192\l{QML Data Models#VisualItemModel}{VisualItemModel}.
193*/
Note: See TracBrowser for help on using the repository browser.