2011-12-14 15:07:05 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2020-02-25 11:24:03 +01:00
|
|
|
** Copyright (C) 2020 The Qt Company Ltd.
|
2016-01-15 14:51:16 +01:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-12-14 15:07:05 +01:00
|
|
|
**
|
2016-01-15 14:51:16 +01:00
|
|
|
** This file is part of the Qt Creator documentation.
|
2011-12-14 15:07:05 +01:00
|
|
|
**
|
2016-01-15 14:51:16 +01:00
|
|
|
** 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.
|
2011-12-14 15:07:05 +01:00
|
|
|
**
|
2016-01-15 14:51:16 +01:00
|
|
|
** GNU Free Documentation License Usage
|
2011-12-14 15:07:05 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Free
|
|
|
|
|
** Documentation License version 1.3 as published by the Free Software
|
2016-01-15 14:51:16 +01:00
|
|
|
** 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.
|
2011-12-14 15:07:05 +01:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
// **********************************************************************
|
|
|
|
|
// NOTE: the sections are not ordered by their logical order to avoid
|
|
|
|
|
// reshuffling the file each time the index order changes (i.e., often).
|
|
|
|
|
// Run the fixnavi.pl script to adjust the links to the index order.
|
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
\page quick-components.html
|
2019-03-29 15:10:22 +01:00
|
|
|
\if defined(qtdesignstudio)
|
2021-03-11 18:08:46 +01:00
|
|
|
\previouspage studio-flow-external-events.html
|
2019-03-29 15:10:22 +01:00
|
|
|
\else
|
2018-08-24 13:46:38 +02:00
|
|
|
\previouspage creator-using-qt-quick-designer.html
|
2019-03-29 15:10:22 +01:00
|
|
|
\endif
|
2021-02-12 18:16:06 +01:00
|
|
|
\nextpage quick-shapes.html
|
2011-12-14 15:07:05 +01:00
|
|
|
|
|
|
|
|
\title Creating Components
|
|
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
A \e component is a reusable building block for a UI.
|
2018-07-11 13:36:37 +02:00
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
\QDS comes with \e {preset components} that you can use in your project.
|
|
|
|
|
These are similar to \e Symbols in Sketch or \e Prefab in Unity.
|
2018-07-11 13:36:37 +02:00
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
Some of the preset components represent simple shapes, text, or images,
|
|
|
|
|
while others represent complex UI controls with full functionality, such
|
|
|
|
|
as spin boxes or sliders.
|
2018-07-11 13:36:37 +02:00
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
You can modify the \e properties of the preset components and combine them
|
|
|
|
|
to build your own components.
|
2018-07-11 13:36:37 +02:00
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
A component is specified within one file (with the file extension
|
|
|
|
|
\e ui.qml or \e .qml). For example, a Button component may be defined
|
|
|
|
|
in \e Button.ui.qml. Typically, the visual appearance of a component
|
|
|
|
|
is defined in a \e {UI file} (ui.qml).
|
2020-10-01 16:48:17 +02:00
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
The \l {Library} view \uicontrol Components tab lists the components that
|
|
|
|
|
have been added to your project.
|
2018-07-11 13:36:37 +02:00
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
\image qmldesigner-qml-components.png "Components"
|
2018-07-11 13:36:37 +02:00
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
\note Use as few components as possible. To minimize the number of
|
|
|
|
|
components, use \l{Adding Property Aliases}{alias properties} and
|
|
|
|
|
\l{Adding States}{states} to create the differences in your component
|
|
|
|
|
instances. We recommend reusing components instead of duplicating them,
|
|
|
|
|
so the components do not need to be processed as completely new component
|
|
|
|
|
types. This reduces the time needed to load and build the application,
|
|
|
|
|
as well as the size of the application package.
|
2020-10-01 16:48:17 +02:00
|
|
|
|
2018-07-11 13:36:37 +02:00
|
|
|
\section1 Adding Components to Designs
|
|
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
\image qmldesigner-editing-components.png "Editing components in Form Editor"
|
2018-07-11 13:36:37 +02:00
|
|
|
|
|
|
|
|
\list 1
|
2020-05-07 09:24:14 +02:00
|
|
|
\li Drag and drop components from \uicontrol Library (1) to
|
|
|
|
|
\uicontrol Navigator (2) or \uicontrol {Form Editor} (3).
|
2020-08-25 17:10:49 +02:00
|
|
|
\li Select components in \uicontrol Navigator to edit the
|
|
|
|
|
values of their properties in \uicontrol Properties.
|
2020-05-07 09:24:14 +02:00
|
|
|
\image qmldesigner-properties-view.png "Properties view"
|
2021-02-22 18:15:55 +01:00
|
|
|
For more information, see \l {Specifying Component Properties}.
|
2020-08-25 17:10:49 +02:00
|
|
|
\li To change the appearance and behavior of your components in ways
|
|
|
|
|
that are not supported out of the box, you can define custom
|
|
|
|
|
properties for your components in the \uicontrol Connections view,
|
|
|
|
|
\uicontrol Properties tab.
|
|
|
|
|
\image qmldesigner-dynamicprops.png "Connections view Properties tab"
|
|
|
|
|
For more information, see \l{Specifying Dynamic Properties}.
|
|
|
|
|
\li To enable users to interact with components, connect the components
|
|
|
|
|
to signals in the \uicontrol Connections view. For example, you can
|
|
|
|
|
specify what happens when a component is clicked.
|
2021-03-04 13:16:36 +01:00
|
|
|
For more information, see \l{Connecting Components to Signals}.
|
2020-08-25 17:10:49 +02:00
|
|
|
\image qmldesigner-connections.png "Connections view Connections tab"
|
|
|
|
|
\li To dynamically change the behavior of an object when another object
|
|
|
|
|
changes, create bindings between components in the
|
2021-02-12 18:16:06 +01:00
|
|
|
\uicontrol {Connection View}, \uicontrol Bindings tab.
|
2020-08-25 17:10:49 +02:00
|
|
|
For more information, see \l{Adding Bindings Between Properties}.
|
2020-05-07 09:24:14 +02:00
|
|
|
\image qmldesigner-bindings.png "Connections view Bindings tab"
|
2020-08-25 17:10:49 +02:00
|
|
|
\li Add states to apply sets of changes to the property values of one
|
|
|
|
|
or several components in the \uicontrol States view.
|
2020-05-07 09:24:14 +02:00
|
|
|
For more information, see \l{Adding States}.
|
|
|
|
|
\li Animate component properties in the \uicontrol Timeline view.
|
2020-04-22 16:06:49 +02:00
|
|
|
For more information, see \l{Creating Animations}.
|
2018-07-11 13:36:37 +02:00
|
|
|
\endlist
|
|
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
\section1 Creating Your Own Components
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2020-11-25 10:34:18 +01:00
|
|
|
You can either use project wizard templates to create custom components and
|
|
|
|
|
controls or \l{Moving Components into Separate Files}{move subcomponents
|
|
|
|
|
into separate files} to make them reusable in other components.
|
|
|
|
|
|
|
|
|
|
\section2 Creating Components from Scratch
|
|
|
|
|
|
|
|
|
|
To use wizard templates to create custom components:
|
|
|
|
|
|
2011-12-14 15:07:05 +01:00
|
|
|
\list 1
|
|
|
|
|
|
2014-12-11 15:43:19 +01:00
|
|
|
\li Select \uicontrol File > \uicontrol {New File or Project} >
|
2019-01-30 14:26:56 +01:00
|
|
|
\if defined(qtcreator)
|
|
|
|
|
\uicontrol Qt > \uicontrol {QML File (Qt Quick 2)} >
|
|
|
|
|
\else
|
|
|
|
|
\uicontrol {Qt Quick Files} > \uicontrol {Qt Quick File} >
|
|
|
|
|
\endif
|
|
|
|
|
\uicontrol Choose to create a new .qml file.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
\note Components are listed in the \uicontrol {My Components}
|
2020-05-07 09:24:14 +02:00
|
|
|
tab in the \uicontrol Library view only if the filename begins with
|
|
|
|
|
a capital letter.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
\li Click \uicontrol Design to open the component file (ui.qml] in
|
|
|
|
|
\uicontrol {Form Editor}.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
\li Drag and drop a component from \uicontrol Library to
|
2017-02-03 15:43:05 +01:00
|
|
|
\uicontrol Navigator or \uicontrol {Form Editor}.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
\li Edit component properties in \uicontrol Properties.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2020-11-25 10:34:18 +01:00
|
|
|
\image qmldesigner-custom-component-properties.png
|
|
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
The available properties depend on the component type. You can
|
2020-11-25 10:34:18 +01:00
|
|
|
\l{Specifying Dynamic Properties}{add properties for
|
|
|
|
|
components} in the \uicontrol Properties tab of the
|
|
|
|
|
\uicontrol {Connection View}.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
|
|
|
|
\endlist
|
|
|
|
|
|
2020-05-07 09:24:14 +02:00
|
|
|
The following sections contain more information about how to use
|
2021-02-12 18:16:06 +01:00
|
|
|
\uicontrol {Form Editor} to edit 2D content and \uicontrol {3D Editor}
|
|
|
|
|
to edit 3D scenes, as well as examples of how to create UI controls
|
|
|
|
|
using basic components:
|
2011-12-14 15:07:05 +01:00
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
|
2021-02-19 10:37:32 +01:00
|
|
|
\li \l{Form Editor}
|
2020-04-21 16:18:10 +02:00
|
|
|
|
2021-03-09 15:17:22 +02:00
|
|
|
\li \l{3D Editor}
|
2021-02-12 18:16:06 +01:00
|
|
|
|
2013-02-06 08:50:23 +01:00
|
|
|
\li \l{Creating Buttons}
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2013-02-06 08:50:23 +01:00
|
|
|
\li \l{Creating Scalable Buttons and Borders}
|
2011-12-14 15:07:05 +01:00
|
|
|
|
|
|
|
|
\endlist
|
|
|
|
|
|
2020-11-12 13:55:16 +01:00
|
|
|
\if defined(qtdesignstudio)
|
|
|
|
|
\include qtdesignstudio-components.qdocinc creating studio components
|
|
|
|
|
\endif
|
|
|
|
|
|
2020-11-25 10:34:18 +01:00
|
|
|
\section2 Moving Components into Separate Files
|
2020-11-18 11:10:18 +01:00
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
An alternative way of creating reusable components is to move them
|
|
|
|
|
into separate component files (.ui.qml). Right-click a component
|
|
|
|
|
in \uicontrol Navigator or \uicontrol {Form Editor} and select
|
2020-11-18 11:10:18 +01:00
|
|
|
\uicontrol {Move Component into Separate File} in the context menu.
|
|
|
|
|
|
|
|
|
|
\image qtcreator-move-component-into-separate-file.png
|
|
|
|
|
|
|
|
|
|
Give the new component a name and select whether properties are set for
|
|
|
|
|
the new component or for the original one.
|
|
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
When you select \uicontrol OK, a new component file is created and a
|
|
|
|
|
reference to the component is added to the code in the current component
|
|
|
|
|
file. The way things look in \uicontrol {Form Editor} does not change.
|
|
|
|
|
|
|
|
|
|
To open the new component file for editing the properties that you want
|
|
|
|
|
to change for all instances of the component, right-click the component
|
|
|
|
|
and then select \uicontrol {Go into Component} in the context menu. For
|
|
|
|
|
additional ways of opening subcomponents, see \l{Moving Within Components}.
|
|
|
|
|
|
2020-11-18 11:10:18 +01:00
|
|
|
For an example of creating a reusable custom component, see
|
|
|
|
|
\if defined(qtcreator)
|
|
|
|
|
\l{Creating a Mobile Application}.
|
|
|
|
|
\else
|
|
|
|
|
\l{Progress Bar}.
|
|
|
|
|
\endif
|
|
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
Custom components are listed in the \uicontrol {My Components} section
|
|
|
|
|
of the \uicontrol Components tab in \uicontrol Library and you can use
|
|
|
|
|
them to build more components.
|
2020-11-25 10:34:18 +01:00
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
\include qtquick-mcu-support.qdocinc mcu qtquick components
|
2020-11-18 11:10:18 +01:00
|
|
|
|
|
|
|
|
\section1 Merging Files with Templates
|
|
|
|
|
|
2021-02-12 18:16:06 +01:00
|
|
|
You can merge the current component file against an existing second
|
|
|
|
|
component file and using the second file in a way similar to using a
|
|
|
|
|
CSS stylesheet.
|
2020-11-18 11:10:18 +01:00
|
|
|
|
|
|
|
|
To use this experimental feature, right-click a component in the
|
|
|
|
|
\uicontrol Navigator or \uicontrol {Form Editor} view and select
|
|
|
|
|
\uicontrol {Merge File with Template} in the context menu.
|
|
|
|
|
|
|
|
|
|
\image qmldesigner-merge-with-template.png "Merge with Template dialog"
|
|
|
|
|
|
|
|
|
|
In the \uicontrol Template field, select the file to use as a template.
|
2011-12-14 15:07:05 +01:00
|
|
|
*/
|