Item LayoutsPositioner items are container items that manage the positions and sizes of items in a declarative user interface. Positioners behave in a similar way to the layout managers used with standard Qt widgets, except that they are also containers in their own right. Positioners make it easier to work with many items when they need to be arranged in a regular layout. PositionersA set of standard positioners are provided in the basic set of Qt Quick graphical elements:
Column
Column items are used to vertically arrange items. The following example uses a Column item to arrange three Rectangle items in an area defined by an outer Item. The spacing property is set to include a small amount of space between the rectangles. Note that, since Column inherits directly from Item, any background color must be added to a parent Rectangle, if desired. Row
Row items are used to horizontally arrange items. The following example uses a Row item to arrange three rounded Rectangle items in an area defined by an outer colored Rectangle. The spacing property is set to include a small amount of space between the rectangles. We ensure that the parent Rectangle is large enough so that there is some space left around the edges of the horizontally centered Row item. Grid
Grid items are used to place items in a grid or table arrangement. The following example uses a Grid item to place four Rectangle items in a 2-by-2 grid. As with the other positioners, the spacing between items can be specified using the spacing property. There is no difference between horizontal and vertical spacing inserted between items, so any additional space must be added within the items themselves. Any empty cells in the grid must be created by defining placeholder items at the appropriate places in the Grid definition. Flow
Flow items are used to place items like words on a page, with rows or columns of non-overlapping items. Flow items arrange items in a similar way to Grid items, with items arranged in lines along one axis (the minor axis), and lines of items placed next to each other along another axis (the major axis). The direction of flow, as well as the spacing between items, are controlled by the flow and spacing properties. The following example shows a Flow item containing a number of Text child items. These are arranged in a similar way to those shown in the screenshots. The main differences between the Grid and Flow positioners are that items inside a Flow will wrap when they run out of space on the minor axis, and items on one line may not be aligned with items on another line if the items do not have uniform sizes. As with Grid items, there is no independent control of spacing between items and between lines of items. Other Ways to Position ItemsThere are several other ways to position items in a user interface. In addition to the basic technique of specifying their coordinates directly, they can be positioned relative to other items with anchors, or used with QML Data Models such as VisualItemModel. |