2020-10-02 12:07:15 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2021-03-16 14:54:45 +01:00
|
|
|
** Copyright (C) 2021 The Qt Company Ltd.
|
2020-10-02 12:07:15 +02:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of the Qt Creator documentation.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU Free Documentation License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Free
|
|
|
|
|
** Documentation License version 1.3 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file included in the packaging of
|
|
|
|
|
** this file. Please review the following information to ensure
|
|
|
|
|
** the GNU Free Documentation License version 1.3 requirements
|
|
|
|
|
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\page qtquick-positioning.html
|
|
|
|
|
\previouspage qtquick-properties.html
|
|
|
|
|
\nextpage qtquick-fonts.html
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
\title Positioning Components
|
2020-10-02 12:07:15 +02:00
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
The position of a \l{glossary-component}{component} in a UI can be either
|
|
|
|
|
absolute or relative to other components. The visual components exist at a
|
|
|
|
|
particular location in the screen coordinate system at any instant in time.
|
|
|
|
|
The x and y coordinates of a visual component are relative to those of its
|
|
|
|
|
visual parent, with the top-left corner having the coordinate (0, 0).
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
If you are designing a static UI,
|
|
|
|
|
\l{Important Concepts In Qt Quick - Positioning#manual-positioning}
|
|
|
|
|
{manual positioning} provides the most efficient form of positioning
|
2021-03-16 14:54:45 +01:00
|
|
|
components. For a dynamic UI, you can employ the following positioning
|
2020-10-02 12:07:15 +02:00
|
|
|
methods:
|
|
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
\li \l{Setting Bindings}
|
|
|
|
|
\li \l{Setting Anchors and Margins}
|
2021-03-16 14:54:45 +01:00
|
|
|
\li \l{Aligning and Distributing Components}
|
2020-10-02 12:07:15 +02:00
|
|
|
\li \l{Using Positioners}
|
|
|
|
|
\li \l{Using Layouts}
|
2021-03-16 14:54:45 +01:00
|
|
|
\li \l{Organizing Components}
|
2020-10-02 12:07:15 +02:00
|
|
|
\endlist
|
|
|
|
|
|
|
|
|
|
\section2 Setting Bindings
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
\l{Positioning with Bindings}{Property binding} is a declarative way of
|
2020-10-02 12:07:15 +02:00
|
|
|
specifying the value of a property. Binding allows a property value to be
|
|
|
|
|
expressed as a JavaScript expression that defines the value relative to
|
|
|
|
|
other property values or data accessible in the application. The property
|
|
|
|
|
value is automatically kept up to date if the other properties or data
|
|
|
|
|
values change.
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
Property bindings are created implicitly whenever a property is assigned a
|
|
|
|
|
JavaScript expression. To set JavaScript expressions as values of properties
|
|
|
|
|
in the \l Properties view, select the \inlineimage icons/action-icon.png
|
2020-10-02 12:07:15 +02:00
|
|
|
(\uicontrol Actions) menu next to a property, and then select
|
|
|
|
|
\uicontrol {Set Binding}.
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
\image qmldesigner-set-expression.png "Actions menu"
|
2020-10-02 12:07:15 +02:00
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
In \uicontrol {Binding Editor}, select a component and a property from
|
|
|
|
|
lists of available components and their properties.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
\image qmldesigner-binding-editor.png "Binding Editor"
|
|
|
|
|
|
|
|
|
|
Alternatively, start typing a
|
|
|
|
|
string and press \key Ctrl+Space to display a list of properties, IDs, and
|
|
|
|
|
code snippets. When you enter a period (.) after a property name, a list of
|
|
|
|
|
available values is displayed. Press \key Enter to accept the first
|
|
|
|
|
suggestion in the list and to complete the code.
|
|
|
|
|
|
|
|
|
|
When a binding is set, the \uicontrol Actions menu icon changes to
|
|
|
|
|
\inlineimage icons/action-icon-binding
|
|
|
|
|
. To remove bindings, select \uicontrol Actions > \uicontrol Reset.
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
You can set bindings also in the \l Connections view. For more
|
2020-10-02 12:07:15 +02:00
|
|
|
information, see \l {Adding Bindings Between Properties}.
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
For more information on the JavaScript environment provided, see
|
2020-10-02 12:07:15 +02:00
|
|
|
\l{Integrating QML and JavaScript}.
|
|
|
|
|
|
|
|
|
|
Bindings are a black box for \QC and using them might have a
|
|
|
|
|
negative impact on performance, so consider setting anchors and margins for
|
2021-03-16 14:54:45 +01:00
|
|
|
components, instead. For example, instead of setting \c {parent.width} for a
|
|
|
|
|
component, you could anchor the component to its sibling components on the
|
|
|
|
|
left and the right.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
\section2 Setting Anchors and Margins
|
|
|
|
|
|
|
|
|
|
In an \l{Important Concepts In Qt Quick - Positioning#anchors}
|
2021-03-16 14:54:45 +01:00
|
|
|
{anchor-based} layout, each component can be thought of as having a set of
|
2020-10-02 12:07:15 +02:00
|
|
|
invisible \e anchor lines: top, bottom, left, right, fill, horizontal
|
|
|
|
|
center, vertical center, and baseline.
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
In \l Properties > \uicontrol Layout, you can set anchors and margins for
|
|
|
|
|
components. To set the anchors of a component, click the anchor buttons.
|
|
|
|
|
You can combine the top/bottom, left/right, and horizontal/vertical anchors
|
|
|
|
|
to anchor components in the corners of the parent component or center them
|
|
|
|
|
horizontally or vertically within the parent component.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
\image qmldesigner-anchor-buttons.png "Anchor buttons"
|
|
|
|
|
|
2020-11-20 15:39:26 +01:00
|
|
|
For convenience, you can click the \inlineimage icons/anchor-fill.png
|
2021-03-16 14:54:45 +01:00
|
|
|
(\uicontrol {Fill to Parent}) toolbar button to apply fill anchors to a
|
|
|
|
|
component and the \inlineimage qtcreator-anchors-reset-icon.png
|
2020-10-02 12:07:15 +02:00
|
|
|
(\uicontrol {Reset Anchors}) button to reset the anchors to their saved
|
|
|
|
|
state.
|
|
|
|
|
|
2021-04-09 13:58:54 +02:00
|
|
|
You can specify the baseline anchor in \l{Text Editor}.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
For performance reasons, you can only anchor a component to its siblings
|
|
|
|
|
and direct parent. By default, a component is anchored to its parent when
|
|
|
|
|
you use the anchor buttons. Select a sibling of the component in the
|
|
|
|
|
\uicontrol Target field to anchor to it instead.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
Arbitrary anchoring is not supported. For example, you cannot specify:
|
|
|
|
|
\c {anchor.left: parent.right}. You have to specify:
|
|
|
|
|
\c {anchor.left: parent.left}. When you use the anchor buttons, anchors to
|
2021-03-16 14:54:45 +01:00
|
|
|
the parent component are always specified to the same side. However, anchors
|
|
|
|
|
to sibling components are specified to the opposite side:
|
|
|
|
|
\c {anchor.left: sibling.right}. This allows you to keep sibling components
|
2020-10-02 12:07:15 +02:00
|
|
|
together.
|
|
|
|
|
|
|
|
|
|
In the following image, \uicontrol{Rectangle 2} is anchored to
|
|
|
|
|
\uicontrol {Rectangle 1} on its left and to the bottom of its parent.
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
\image qmldesigner-anchors.png "Anchoring sibling components"
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
The anchors for \uicontrol{Rectangle 2} are specified as follows in code:
|
|
|
|
|
|
|
|
|
|
\qml
|
|
|
|
|
Rectangle {
|
|
|
|
|
id: rectangle2
|
|
|
|
|
anchors.left: rectangle1.right
|
2021-04-22 08:57:55 +03:00
|
|
|
anchors.leftMargin: 78
|
2020-10-02 12:07:15 +02:00
|
|
|
anchors.bottom: parent.bottom
|
2021-04-22 08:57:55 +03:00
|
|
|
anchors.bottomMargin: 200
|
2020-10-02 12:07:15 +02:00
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
\endqml
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
Margins specify the amount of empty space to leave to the outside of a
|
|
|
|
|
component. Margins only have meaning for anchors. They do not take any
|
|
|
|
|
effect when using layouts or absolute positioning.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
\section2 Aligning and Distributing Components
|
2020-10-02 12:07:15 +02:00
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
When you're working with a group of components, you can select them to align
|
|
|
|
|
and distribute them evenly. As the positions of the components are fixed,
|
|
|
|
|
you cannot apply these functions to anchored components. For scalability,
|
|
|
|
|
you can anchor the aligned and distributed components when your design is
|
|
|
|
|
ready.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
\image qmldesigner-alignment.png "Aligning sibling components"
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
Select the buttons in the \uicontrol Align group to align the top/bottom
|
2021-03-16 14:54:45 +01:00
|
|
|
or left/right edges of the components in the group to the one farthest away
|
|
|
|
|
from the center of the group. For example, when left-aligning, the
|
|
|
|
|
components are aligned to the leftmost component. You can also align the
|
|
|
|
|
horizontal/vertical centers of components, or both, as in the image above.
|
|
|
|
|
|
|
|
|
|
In the \uicontrol {Align to} field, select whether to align the components
|
|
|
|
|
in respect to the selection, the root component, or a \e {key component}
|
|
|
|
|
that you select in the \uicontrol {Key object} field. The key component must
|
|
|
|
|
be a part of the selection.
|
|
|
|
|
|
|
|
|
|
You can distribute either \e components or the \e spacing between them.
|
|
|
|
|
If the components or spacing cannot be distributed to equal pixel values
|
|
|
|
|
without ending up with half pixels, you receive a notification. You can
|
|
|
|
|
either allow \QDS to distribute components or spacing using the closest
|
|
|
|
|
values possible or tweak your design so that the components and spacing
|
|
|
|
|
can be distributed perfectly.
|
|
|
|
|
|
|
|
|
|
When distributing components, you can select whether the distance between
|
2020-10-02 12:07:15 +02:00
|
|
|
them is calculated from their top/bottom or left/right edges or their
|
|
|
|
|
horizontal/vertical center.
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
\image qmldesigner-distribute-objects.png "Distribute components buttons"
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
You can distribute spacing either evenly within a target area or at
|
|
|
|
|
specified distances, calculated from a starting point.
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
You can select the orientation in which the components are distributed
|
|
|
|
|
evenly within the target area: horizontally along the x axis or vertically
|
|
|
|
|
along the y axis.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
\image qmldesigner-distribute-spacing-evenly.png "Distribute spacing evenly"
|
|
|
|
|
|
|
|
|
|
Alternatively, you can distribute spacing in pixels by selecting one of the
|
|
|
|
|
starting point buttons: left/right or top/bottom edge of the target area,
|
2021-03-16 14:54:45 +01:00
|
|
|
or its horizontal/vertical center. Note that some components might end up
|
|
|
|
|
outside the target area.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
\image qmldesigner-distribute-spacing-pixels.png "Distribute spacing in pixels"
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
You can set the space between components in pixels. You can
|
2020-10-02 12:07:15 +02:00
|
|
|
disable the distribution of spacing in pixels by clicking
|
2020-11-20 15:39:26 +01:00
|
|
|
the \inlineimage icons/distribute-origin-none.png
|
2020-10-02 12:07:15 +02:00
|
|
|
button.
|
|
|
|
|
|
|
|
|
|
\section2 Using Positioners
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
Positioner components are containers that manage the positions of their
|
|
|
|
|
child components. For many use cases, the best positioner to use is a simple
|
|
|
|
|
column, row, flow, or grid. You can use the components available in
|
|
|
|
|
\l Library > \uicontrol Components > \uicontrol {Default Components} >
|
|
|
|
|
\uicontrol Positioner to position the children of a component in these
|
|
|
|
|
formations in the most efficient manner possible.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
To position several components in a \uicontrol Column, \uicontrol Row,
|
|
|
|
|
\uicontrol Flow, or \uicontrol Grid, select the components in
|
|
|
|
|
\l {Form Editor}, and then select \uicontrol Position in
|
2020-10-02 12:07:15 +02:00
|
|
|
the context menu.
|
|
|
|
|
|
|
|
|
|
\section3 Column Positioner
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
A \uicontrol Column positions its child components along a single column.
|
2020-10-02 12:07:15 +02:00
|
|
|
It can be used as a convenient way to vertically position a series of
|
2021-03-16 14:54:45 +01:00
|
|
|
components without using anchors.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
\image qtquick-positioner-column-properties.png "Column properties"
|
|
|
|
|
|
|
|
|
|
For all positioners, you can specify the spacing between the child
|
2021-03-16 14:54:45 +01:00
|
|
|
components that they contain in the \uicontrol Spacing field.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
In addition, you can specify the vertical and horizontal padding between
|
2021-03-16 14:54:45 +01:00
|
|
|
content and the left, right, top, and bottom edges of components as values
|
|
|
|
|
of the fields in the \uicontrol Padding group.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
\section3 Row and Flow Positioners
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
A \uicontrol Row positions its child components along a single row. It can
|
|
|
|
|
be used as a convenient way to horizontally position a series of components
|
|
|
|
|
without using anchors.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
The \uicontrol Flow component positions its child components like words on a
|
|
|
|
|
page, wrapping them to create rows or columns of components.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
\image qtquick-positioner-flow-properties.png "Flow properties"
|
|
|
|
|
|
|
|
|
|
For flow and row positioners, you can also set the direction of a flow to
|
|
|
|
|
either left-to-right or top-to-bottom in the \uicontrol Flow field.
|
2021-03-16 14:54:45 +01:00
|
|
|
Components are positioned next to to each other according to the value you
|
|
|
|
|
set in the \uicontrol {Layout direction} field until the width or height of
|
|
|
|
|
the Flow component is exceeded, then wrapped to the next row or column.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
You can set the layout direction to either \uicontrol LeftToRight or
|
|
|
|
|
\uicontrol RightToLeft in the \uicontrol {Layout direction} field. If
|
|
|
|
|
the width of the row is explicitly set, the left anchor remains to the
|
|
|
|
|
left of the row and the right anchor remains to the right of it.
|
|
|
|
|
|
|
|
|
|
\section3 Grid Positioner
|
|
|
|
|
|
|
|
|
|
A \uicontrol Grid creates a grid of cells that is large enough to hold all
|
2021-03-16 14:54:45 +01:00
|
|
|
of its child components, and places these components in the cells from left
|
|
|
|
|
to right and top to bottom. Each component is positioned at the top-left
|
|
|
|
|
corner of its cell with position (0, 0).
|
2020-10-02 12:07:15 +02:00
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
\QC generates the grid based on the positions of the child components in
|
|
|
|
|
\l {Form Editor}. You can modify the number of rows and columns in the
|
|
|
|
|
\uicontrol Rows and \uicontrol Columns fields.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
\image qtquick-positioner-grid-properties.png "Grid properties"
|
|
|
|
|
|
|
|
|
|
In addition to the flow and layout direction, you can set the horizontal
|
2021-03-16 14:54:45 +01:00
|
|
|
and vertical alignment of grid components. By default, grid components are
|
|
|
|
|
vertically aligned to the top. Horizontal alignment follows the value of the
|
2020-10-02 12:07:15 +02:00
|
|
|
\uicontrol {Layout direction} field. For example, when layout direction is
|
2021-03-16 14:54:45 +01:00
|
|
|
set to \uicontrol LeftToRight, the components are aligned on the left.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
To mirror the layout, set the layout direction to \uicontrol RightToLeft.
|
2021-03-16 14:54:45 +01:00
|
|
|
To also mirror the horizontal alignment of components, select
|
2020-10-02 12:07:15 +02:00
|
|
|
\uicontrol AlignRight in the \uicontrol {Horizontal item alignment} field.
|
|
|
|
|
|
|
|
|
|
\section3 Summary of Positioners
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
The following table lists the positioners that you can use to arrange
|
|
|
|
|
components in UIs. They are available in \l Library > \uicontrol Components
|
|
|
|
|
> \uicontrol {Default Components} > \uicontrol Positioner.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
\table
|
|
|
|
|
\header
|
|
|
|
|
\li Icon
|
|
|
|
|
\li Name
|
|
|
|
|
\li Purpose
|
|
|
|
|
\row
|
|
|
|
|
\li \inlineimage column-positioner-icon-16px.png
|
|
|
|
|
\li \l[QtQuick] {Column}
|
2021-03-16 14:54:45 +01:00
|
|
|
\li Arranges its child components vertically.
|
2020-10-02 12:07:15 +02:00
|
|
|
\row
|
|
|
|
|
\li \inlineimage row-positioner-icon-16px.png
|
|
|
|
|
\li \l[QtQuick] {Row}
|
2021-03-16 14:54:45 +01:00
|
|
|
\li Arranges its child components horizontally.
|
2020-10-02 12:07:15 +02:00
|
|
|
\row
|
|
|
|
|
\li \inlineimage grid-positioner-icon-16px.png
|
|
|
|
|
\li \l[QtQuick] {Grid}
|
2021-03-16 14:54:45 +01:00
|
|
|
\li Arranges its child components so that they are aligned in a grid and
|
2020-10-02 12:07:15 +02:00
|
|
|
are not overlapping.
|
|
|
|
|
\row
|
|
|
|
|
\li \inlineimage flow-positioner-icon-16px.png
|
|
|
|
|
\li \l[QtQuick] {Flow}
|
2021-03-16 14:54:45 +01:00
|
|
|
\li Arranges its child components side by side, wrapping as necessary.
|
2020-10-02 12:07:15 +02:00
|
|
|
\endtable
|
|
|
|
|
|
|
|
|
|
\section2 Using Layouts
|
|
|
|
|
|
|
|
|
|
\if defined(qtcreator)
|
|
|
|
|
Since Qt 5.1, you can use QML types in the \l{qtquicklayouts-index.html}
|
2021-03-16 14:54:45 +01:00
|
|
|
{Qt Quick Layouts} module to arrange components in UIs.
|
2020-10-02 12:07:15 +02:00
|
|
|
\else
|
2021-03-16 14:54:45 +01:00
|
|
|
You can use the components available in \l Library > \uicontrol Components
|
|
|
|
|
> \uicontrol {Qt Quick Layouts} to arrange components in UIs.
|
2020-10-02 12:07:15 +02:00
|
|
|
\endif
|
|
|
|
|
Unlike positioners, layouts manage both the positions and sizes of their
|
2021-03-16 14:54:45 +01:00
|
|
|
child components, and are therefore well suited for dynamic and resizable
|
|
|
|
|
UIs. However, this means that you should not specify fixed positions and
|
|
|
|
|
sizes for the child components in the \l{2D Geometry}{Geometry} group in
|
|
|
|
|
\l Properties, unless their implicit sizes are not satisfactory.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
You can use anchors or the width and height properties of the layout itself
|
2021-03-16 14:54:45 +01:00
|
|
|
to specify its size in respect to its non-layout parent component. However,
|
|
|
|
|
do not anchor the child components within layouts.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
To arrange several components in a column, row, grid, or
|
|
|
|
|
\uicontrol {Stack Layout}, select the components in \l {Form Editor},
|
2020-10-02 12:07:15 +02:00
|
|
|
and then select \uicontrol Layout in the context menu.
|
|
|
|
|
|
|
|
|
|
You can also click the \inlineimage column.png
|
|
|
|
|
(\uicontrol {Column Layout}), \inlineimage row.png
|
|
|
|
|
(\uicontrol {Row Layout}), and \inlineimage grid.png
|
|
|
|
|
(\uicontrol {Grid Layout}) toolbar buttons to apply
|
2021-03-16 14:54:45 +01:00
|
|
|
layouts to the selected components.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
To make a component within a layout as wide as possible while respecting the
|
|
|
|
|
given constraints, select the component in \uicontrol {Form Editor}, and
|
|
|
|
|
then select \uicontrol Layout > \uicontrol {Fill Width} in the context menu.
|
|
|
|
|
To make the component as high as possible, select \uicontrol {Fill Height}.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
\section3 Layout Properties
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
A \uicontrol {Grid Layout} component provides a way of dynamically
|
|
|
|
|
arranging components in a grid. If the grid layout is resized, all
|
|
|
|
|
its child components are rearranged. If you want a layout with just
|
|
|
|
|
one row or one column, use the \uicontrol {Row Layout} or
|
|
|
|
|
\uicontrol {Column Layout} component.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
The child components of row and column layout components are automatically
|
|
|
|
|
positioned either horizontally from left to right as rows or vertically from
|
|
|
|
|
top to bottom as columns. The number of the child components determines the
|
|
|
|
|
width of the row or the height of the column. You can specify the spacing
|
|
|
|
|
between the child components in the \uicontrol Spacing field.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
The child components of grid layout components are arranged according to the
|
2020-10-02 12:07:15 +02:00
|
|
|
\uicontrol Flow property. When the direction of a flow is set to
|
2021-03-16 14:54:45 +01:00
|
|
|
\uicontrol LeftToRight, child components are positioned next to to each
|
2020-10-02 12:07:15 +02:00
|
|
|
other until the the number of \uicontrol Columns is reached. Then,
|
|
|
|
|
the auto-positioning wraps back to the beginning of the next row.
|
|
|
|
|
|
|
|
|
|
\image qtquick-layout-grid-properties.png "Grid Layout properties"
|
|
|
|
|
|
|
|
|
|
If you set the direction of the flow to \uicontrol TopToBottom, child
|
2021-03-16 14:54:45 +01:00
|
|
|
components are auto-positioned vertically using the value of the
|
|
|
|
|
\uicontrol Rows field to determine the maximum number of rows.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
You can set the layout direction to either \uicontrol LeftToRight or
|
|
|
|
|
\uicontrol RightToLeft in the \uicontrol {Layout direction} field.
|
2021-03-16 14:54:45 +01:00
|
|
|
When you select \uicontrol RightToLeft, the alignment of the components
|
2020-10-02 12:07:15 +02:00
|
|
|
will be mirrored.
|
|
|
|
|
|
|
|
|
|
You can specify the spacing between rows and columns in the
|
|
|
|
|
\uicontrol {Row spacing} and \uicontrol {Column spacing} fields.
|
|
|
|
|
|
|
|
|
|
\section3 Stack Layout
|
|
|
|
|
|
|
|
|
|
\image qtquick-designer-stacked-view.png
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
To add components to a \uicontrol {Stack Layout}, select the
|
2020-10-02 12:07:15 +02:00
|
|
|
\inlineimage plus.png
|
2021-03-16 14:54:45 +01:00
|
|
|
button next to the component name in \l {Form Editor}.
|
|
|
|
|
To move between components, select the \inlineimage prev.png
|
2020-10-02 12:07:15 +02:00
|
|
|
(\uicontrol Previous) and \inlineimage next.png
|
|
|
|
|
(\uicontrol Next) buttons.
|
|
|
|
|
|
2021-04-22 08:57:55 +03:00
|
|
|
To add a tab bar to a stack layout, right-click on the
|
|
|
|
|
\uicontrol {Stack Layout} in \uicontrol Navigator to access the context menu,
|
|
|
|
|
and select \uicontrol {Stacked Container} > \uicontrol {Add Tab Bar}.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
To raise or lower the stacking order of a component, select
|
2020-10-02 12:07:15 +02:00
|
|
|
\uicontrol {Stacked Container} > \uicontrol {Increase Index} or
|
|
|
|
|
\uicontrol {Decrease Index}.
|
|
|
|
|
|
|
|
|
|
\section3 Summary of Layouts
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
The following table lists the layout components that you can use to arrange
|
|
|
|
|
components in UIs. They are available in \l Library > \uicontrol Components
|
|
|
|
|
> \uicontrol {Qt Quick Layouts}.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
\table
|
|
|
|
|
\header
|
|
|
|
|
\li Icon
|
|
|
|
|
\li Name
|
|
|
|
|
\li Purpose
|
|
|
|
|
\row
|
|
|
|
|
\li \inlineimage column-layouts-icon-16px.png
|
|
|
|
|
\li \l{ColumnLayout}{Column Layout}
|
|
|
|
|
\li Provides a grid layout with only one column.
|
|
|
|
|
\row
|
|
|
|
|
\li\inlineimage row-layouts-icon-16px.png
|
|
|
|
|
\li \l{RowLayout}{Row Layout}
|
|
|
|
|
\li Provides a grid layout with only one row.
|
|
|
|
|
\row
|
|
|
|
|
\li \inlineimage grid-layouts-icon-16px.png
|
|
|
|
|
\li \l{GridLayout}{Grid Layout}
|
2021-03-16 14:54:45 +01:00
|
|
|
\li Provides a way of dynamically arranging components in a grid.
|
2020-10-02 12:07:15 +02:00
|
|
|
\row
|
|
|
|
|
\li \inlineimage stack-layouts-icon-16px.png
|
|
|
|
|
\li \l{StackLayout}{Stack Layout}
|
2021-03-16 14:54:45 +01:00
|
|
|
\li Provides a stack of components where only one component is
|
|
|
|
|
visible at a time.
|
2020-10-02 12:07:15 +02:00
|
|
|
\endtable
|
|
|
|
|
|
|
|
|
|
|
2021-03-16 14:54:45 +01:00
|
|
|
\section2 Organizing Components
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
The following table lists the UI controls that you can use to
|
2021-03-16 14:54:45 +01:00
|
|
|
organize components in UIs (since Qt 5.7). They are available in
|
|
|
|
|
\l Library > \uicontrol Components > \uicontrol {Qt Quick Controls}.
|
2020-10-02 12:07:15 +02:00
|
|
|
|
|
|
|
|
\table
|
|
|
|
|
\header
|
|
|
|
|
\li Icon
|
|
|
|
|
\li Name
|
|
|
|
|
\li Purpose
|
|
|
|
|
\row
|
|
|
|
|
\li \inlineimage icons/frame-icon16.png
|
|
|
|
|
\li \l [QtQuickControls]{Frame}
|
|
|
|
|
\li A visual frame around a group of controls.
|
|
|
|
|
\row
|
|
|
|
|
\li \inlineimage icons/groupbox-icon16.png
|
|
|
|
|
\li \l [QtQuickControls]{GroupBox}{Group Box}
|
|
|
|
|
\li A titled visual frame around a group of controls.
|
|
|
|
|
\row
|
|
|
|
|
\li \inlineimage icons/page-icon16.png
|
|
|
|
|
\li \l [QtQuickControls]{Page}
|
|
|
|
|
\li A styled page control with support for a header and footer.
|
|
|
|
|
\row
|
|
|
|
|
\li \inlineimage icons/pane-icon16.png
|
|
|
|
|
\li \l [QtQuickControls]{Pane}
|
|
|
|
|
\li A background that matches the application style and theme.
|
|
|
|
|
\endtable
|
|
|
|
|
*/
|