[844] | 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 |
|
---|
| 34 | Positioner items are container items that manage the positions and sizes of
|
---|
| 35 | items in a declarative user interface. Positioners behave in a similar way to
|
---|
| 36 | the \l{Widgets and Layouts}{layout managers} used with standard Qt widgets,
|
---|
| 37 | except that they are also containers in their own right.
|
---|
| 38 |
|
---|
| 39 | Positioners and repeaters make it easier to work with many items when they need
|
---|
| 40 | to be arranged in a regular layout.
|
---|
| 41 |
|
---|
| 42 | \section1 Positioners
|
---|
| 43 |
|
---|
| 44 | A set of standard positioners are provided in the basic set of Qt Quick
|
---|
| 45 | graphical 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
|
---|
| 61 | uses a Column item to arrange three \l Rectangle items in an area defined
|
---|
| 62 | by an outer \l Item. The \l{Column::spacing}{spacing} property is set to
|
---|
| 63 | include a small amount of space between the rectangles.
|
---|
| 64 |
|
---|
| 65 | \clearfloat
|
---|
| 66 | \snippet doc/src/snippets/declarative/column/column.qml document
|
---|
| 67 |
|
---|
| 68 | Note that, since Column inherits directly from Item, any background color
|
---|
| 69 | must 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
|
---|
| 78 | uses a Row item to arrange three rounded \l Rectangle items in an area defined
|
---|
| 79 | by an outer colored Rectangle. The \l{Row::spacing}{spacing} property is set to
|
---|
| 80 | include a small amount of space between the rectangles.
|
---|
| 81 |
|
---|
| 82 | We ensure that the parent Rectangle is large enough so that there is some space
|
---|
| 83 | left 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.
|
---|
| 95 | The following example uses a Grid item to place four \l Rectangle items
|
---|
| 96 | in a 2-by-2 grid. As with the other positioners, the spacing between items
|
---|
| 97 | can be specified using the \l{Grid::spacing}{spacing} property.
|
---|
| 98 |
|
---|
| 99 | \clearfloat
|
---|
| 100 | \snippet doc/src/snippets/declarative/grid/grid-spacing.qml document
|
---|
| 101 |
|
---|
| 102 | There is no difference between horizontal and vertical spacing inserted
|
---|
| 103 | between items, so any additional space must be added within the items
|
---|
| 104 | themselves.
|
---|
| 105 |
|
---|
| 106 | Any empty cells in the grid must be created by defining placeholder items
|
---|
| 107 | at 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
|
---|
| 117 | columns of non-overlapping items.
|
---|
| 118 |
|
---|
| 119 | Flow items arrange items in a similar way to \l Grid items, with items
|
---|
| 120 | arranged in lines along one axis (the minor axis), and lines of items
|
---|
| 121 | placed next to each other along another axis (the major axis). The
|
---|
| 122 | direction of flow, as well as the spacing between items, are controlled
|
---|
| 123 | by the \l{Flow::}{flow} and \l{Flow::}{spacing} properties.
|
---|
| 124 |
|
---|
| 125 | The following example shows a Flow item containing a number of \l Text
|
---|
| 126 | child items. These are arranged in a similar way to those shown in the
|
---|
| 127 | screenshots.
|
---|
| 128 |
|
---|
| 129 | \clearfloat
|
---|
| 130 | \snippet doc/src/snippets/declarative/flow.qml document
|
---|
| 131 |
|
---|
| 132 | The main differences between the Grid and Flow positioners are that items
|
---|
| 133 | inside a Flow will wrap when they run out of space on the minor axis, and
|
---|
| 134 | items on one line may not be aligned with items on another line if the
|
---|
| 135 | items do not have uniform sizes. As with Grid items, there is no independent
|
---|
| 136 | control 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 |
|
---|
| 144 | Repeaters create items from a template for use with positioners, using data
|
---|
| 145 | from a model. Combining repeaters and positioners is an easy way to lay out
|
---|
| 146 | lots of items. A \l Repeater item is placed inside a positioner, and generates
|
---|
| 147 | items that the enclosing positioner arranges.
|
---|
| 148 |
|
---|
| 149 | Each Repeater creates a number of items by combining each element of data
|
---|
| 150 | from a model, specified using the \l{Repeater::model}{model} property, with
|
---|
| 151 | the template item, defined as a child item within the Repeater.
|
---|
| 152 | The total number of items is determined by the amount of data in the model.
|
---|
| 153 |
|
---|
| 154 | The following example shows a repeater used with a \l{#Grid}{Grid} item to
|
---|
| 155 | arrange a set of Rectangle items. The Repeater item creates a series of 24
|
---|
| 156 | rectangles 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 |
|
---|
| 161 | The number of items created by a Repeater is held by its \l{Repeater::}{count}
|
---|
| 162 | property. It is not possible to set this property to determine the number of
|
---|
| 163 | items to be created. Instead, as in the above example, we use an integer as
|
---|
| 164 | the model. This is explained in the \l{QML Data Models#An Integer}{QML Data Models}
|
---|
| 165 | document.
|
---|
| 166 |
|
---|
| 167 | It is also possible to use a delegate as the template for the items created
|
---|
| 168 | by a Repeater. This is specified using the \l{Repeater::}{delegate} property.
|
---|
| 169 |
|
---|
| 170 | \section1 Using Transitions
|
---|
| 171 |
|
---|
| 172 | Transitions can be used to animate items that are added to, moved within,
|
---|
| 173 | or removed from a positioner.
|
---|
| 174 |
|
---|
| 175 | Transitions for adding items apply to items that are created as part of a
|
---|
| 176 | positioner, as well as those that are reparented to become children of a
|
---|
| 177 | positioner.
|
---|
| 178 | Transitions for removing items apply to items within a positioner that are
|
---|
| 179 | deleted, as well as those that are removed from a positioner and given new
|
---|
| 180 | parents in a document.
|
---|
| 181 |
|
---|
| 182 | Additionally, changing the opacity of items to zero will cause them to
|
---|
| 183 | disappear using the remove transition, and making the opacity non-zero will
|
---|
| 184 | cause them to appear using the add transition.
|
---|
| 185 |
|
---|
| 186 | \section1 Other Ways to Position Items
|
---|
| 187 |
|
---|
| 188 | There are several other ways to position items in a user interface. In addition
|
---|
| 189 | to the basic technique of specifying their coordinates directly, they can be
|
---|
| 190 | positioned relative to other items with \l{anchor-layout}{anchors}, or used
|
---|
| 191 | with \l{QML Data Models} such as
|
---|
| 192 | \l{QML Data Models#VisualItemModel}{VisualItemModel}.
|
---|
| 193 | */
|
---|