Layout QML Type | Qt Quick 6.7.3
Description: Provides attached properties for items pushed onto a GridLayout, RowLayout or ColumnLayout.

- Qt 6.7
- Qt Quick
- QML Types
- QtQuick.Layouts
- Layout
- Qt 6.7.3 Reference Documentation

# Layout QML Type

Provides attached properties for items pushed onto a GridLayout, RowLayout or ColumnLayout. More...

Import Statement: | import QtQuick.Layouts

- List of all members, including inherited members

## Attached Properties

- alignment : Qt.Alignment
- bottomMargin : real `(since QtQuick.Layouts 1.2)`
- column : int
- columnSpan : int
- fillHeight : bool
- fillWidth : bool
- horizontalStretchFactor : int `(since Qt 6.5)`
- leftMargin : real `(since QtQuick.Layouts 1.2)`
- margins : real `(since QtQuick.Layouts 1.2)`
- maximumHeight : real
- maximumWidth : real
- minimumHeight : real
- minimumWidth : real
- preferredHeight : real
- preferredWidth : real
- rightMargin : real `(since QtQuick.Layouts 1.2)`
- row : int
- rowSpan : int
- topMargin : real `(since QtQuick.Layouts 1.2)`
- verticalStretchFactor : int `(since Qt 6.5)`

## Detailed Description

An object of type Layout is attached to children of the layout to provide layout specific information about the item. The properties of the attached object influence how the layout will arrange the items.

For instance, you can specify minimumWidth, preferredWidth, and maximumWidth if the default values are not satisfactory.

When a layout is resized, items may grow or shrink. Due to this, items have a minimum size, preferred size and a maximum size.

If minimum size has not been explicitly specified on an item, the size is set to `0`. If maximum size has not been explicitly specified on an item, the size is set to `Number.POSITIVE_INFINITY`.

For layouts, the implicit minimum and maximum sizes depend on the content of the layouts.

The fillWidth and fillHeight properties can either be `true` or `false`. If they are `false`, the item's size will be fixed to its preferred size. Otherwise, it will grow or shrink between its minimum and maximum size as the layout is resized. If there are multiple items with fillWidth (or fillHeight) set to `true`, the layout will grow or shrink the items relative to the ratio of their preferred size.

For more details on the layout algorithm, see also the Qt Quick Layouts Overview.

Note: Do not bind to the x, y, width, or height properties of items in a layout, as this would conflict with the goals of Layout, and can also cause binding loops. The width and height properties are used by the layout engine to store the current size of items as calculated from the minimum/preferred/maximum attached properties, and can be ovewritten each time the items are laid out. Use Layout.preferredWidth and Layout.preferredHeight, or implicitWidth and implicitHeight to specify the preferred size of items.

See also GridLayout, RowLayout, and ColumnLayout.

## Attached Property Documentation

Layout.alignment : Qt.Alignment

This property allows you to specify the alignment of an item within the cell(s) it occupies.

The default value is `0`, which means it will be `Qt.AlignVCenter | Qt.AlignLeft`. These defaults also apply if only a horizontal or vertical flag is specified: if only a horizontal flag is specified, the default vertical flag will be `Qt.AlignVCenter`, and if only a vertical flag is specified, the default horizontal flag will be `Qt.AlignLeft`.

A valid alignment is a combination of the following flags:

- Qt::AlignLeft
- Qt::AlignHCenter
- Qt::AlignRight
- Qt::AlignTop
- Qt::AlignVCenter
- Qt::AlignBottom
- Qt::AlignBaseline

Layout.bottomMargin : real `[since QtQuick.Layouts 1.2]`

Specifies the bottom margin outside of an item. If the value is not set, it will use the value from margins.

This property was introduced in QtQuick.Layouts 1.2.

See also margins.

Layout.column : int

This property allows you to specify the column position of an item in a GridLayout.

If both row and this property are not set, it is up to the layout to assign a cell to the item.

The default value is `0`.

See also row and columnSpan.

Layout.columnSpan : int

This property allows you to specify the column span of an item in a GridLayout.

The default value is `1`.

See also rowSpan and column.

Layout.fillHeight : bool

If this property is `true`, the item will be as tall as possible while respecting the given constraints. If the property is `false`, the item will have a fixed height set to the preferred height. The default depends on implicit (built-in) size policy of the item.

See also fillWidth.

Layout.fillWidth : bool

If this property is `true`, the item will be as wide as possible while respecting the given constraints. If the property is `false`, the item will have a fixed width set to the preferred width. The default depends on implicit (built-in) size policy of item.

See also fillHeight.

Layout.horizontalStretchFactor : int `[since Qt 6.5]`

This property allows you to specify the horizontal stretch factor. By default, two identical items arranged in a linear layout will have the same size, but if the first item has a stretch factor of 1 and the second item has a stretch factor of 2, the first item will aim to get 1/3 of the available space, and the second will aim to get 2/3 of the available space. Note that, whether they become exactly 1/3 and 2/3 of the available space depends on their size hints. This is because when e.g a horizontal layout is shown in its minimum width all its child items will consequently also have their minimum width.

Likewise, when a horizontal layout has its preferred width, all child items will have their preferred widths, and when a horizontal layout has its maximum width, all child items will have their maximum widths. This strategy is applied regardless of what the individual stretch factors are. As a consequence of this, stretch factors will only determine the growth rate of child items between the preferredWidth and maximumWidth range.

The default value is `-1`, which means that no stretch factor is applied.

Note: This requires that Layout::fillWidth is set to true

This property was introduced in Qt 6.5.

See also verticalStretchFactor.

Layout.leftMargin : real `[since QtQuick.Layouts 1.2]`

Specifies the left margin outside of an item. If the value is not set, it will use the value from margins.

This property was introduced in QtQuick.Layouts 1.2.

See also margins.

Layout.margins : real `[since QtQuick.Layouts 1.2]`

Sets the margins outside of an item to all have the same value. The item itself does not evaluate its own margins. It is the parent's responsibility to decide if it wants to evaluate the margins.

Specifically, margins are only evaluated by ColumnLayout, RowLayout, GridLayout, and other layout-like containers, such as SplitView, where the effective cell size of an item will be increased as the margins are increased.

Therefore, if an item with margins is a child of another `Item`, its position, size and implicit size will remain unchanged.

Combining margins with alignment will align the item including its margins. For instance, a vertically-centered Item with a top margin of `1` and a bottom margin of `9` will cause the Items effective alignment within the cell to be 4 pixels above the center.

The default value is `0`.

This property was introduced in QtQuick.Layouts 1.2.

See also leftMargin, topMargin, rightMargin, and bottomMargin.

Layout.maximumHeight : real

The default value is the item's implicit maximum height.

If the item is a layout, the implicit maximum height will be the maximum height the layout can have without any of its items growing beyond their maximum height. The implicit maximum height for any other item is `Number.POSITIVE_INFINITY`.

Setting this value to `-1` will reset the height back to its implicit maximum height.

See also minimumHeight and preferredHeight.

Layout.maximumWidth : real

This property holds the maximum width of an item in a layout. The default value is the item's implicit maximum width.

If the item is a layout, the implicit maximum width will be the maximum width the layout can have without any of its items growing beyond their maximum width. The implicit maximum width for any other item is `Number.POSITIVE_INFINITY`.

Setting this value to `-1` will reset the width back to its implicit maximum width.

See also minimumWidth and preferredWidth.

Layout.minimumHeight : real

This property holds the minimum height of an item in a layout. The default value is the item's implicit minimum height.

If the item is a layout, the implicit minimum height will be the minimum height the layout can have without any of its items shrinking below their minimum height. The implicit minimum height for any other item is `0`.

Setting this value to -1 will reset the height back to its implicit minimum height.

See also preferredHeight and maximumHeight.

Layout.minimumWidth : real

This property holds the minimum width of an item in a layout. The default value is the item's implicit minimum width.

If the item is a layout, the implicit minimum width will be the minimum width the layout can have without any of its items shrinking below their minimum width. The implicit minimum width for any other item is `0`.

Setting this value to -1 will reset the width back to its implicit minimum width.

See also preferredWidth and maximumWidth.

Layout.preferredHeight : real

This property holds the preferred height of an item in a layout. If the preferred height is `-1` it will be ignored, and the layout will use implicitHeight instead. The default is `-1`.

See also minimumHeight and maximumHeight.

Layout.preferredWidth : real

This property holds the preferred width of an item in a layout. If the preferred width is `-1` it will be ignored, and the layout will use implicitWidth instead. The default is `-1`.

See also minimumWidth and maximumWidth.

Layout.rightMargin : real `[since QtQuick.Layouts 1.2]`

Specifies the right margin outside of an item. If the value is not set, it will use the value from margins.

This property was introduced in QtQuick.Layouts 1.2.

See also margins.

Layout.row : int

This property allows you to specify the row position of an item in a GridLayout.

If both column and this property are not set, it is up to the layout to assign a cell to the item.

The default value is `0`.

See also column and rowSpan.

Layout.rowSpan : int

This property allows you to specify the row span of an item in a GridLayout.

The default value is `1`.

See also columnSpan and row.

Layout.topMargin : real `[since QtQuick.Layouts 1.2]`

Specifies the top margin outside of an item. If the value is not set, it will use the value from margins.

This property was introduced in QtQuick.Layouts 1.2.

See also margins.

Layout.verticalStretchFactor : int `[since Qt 6.5]`

This property allows you to specify the vertical stretch factor. By default, two identical items arranged in a linear layout will have the same size, but if the first item has a stretch factor of 1 and the second item has a stretch factor of 2, the first item will aim to get 1/3 of the available space, and the second will aim to get 2/3 of the available space. Note that, whether they become exactly 1/3 and 2/3 of the available space depends on their size hints. This is because when e.g a vertical layout is shown in its minimum height all its child items will consequently also have their minimum height.

Likewise, when a vertical layout has its preferred height, all child items will have their preferred heights, and when a vertical layout has its maximum height, all child items will have their maximum heights. This strategy is applied regardless of what the individual stretch factors are. As a consequence of this, stretch factors will only determine the growth rate of child items between the preferredHeight and maximumHeight range.

The default value is `-1`, which means that no stretch factor is applied.

Note: This requires that Layout::fillHeight is set to true

This property was introduced in Qt 6.5.

See also horizontalStretchFactor.