Doc: Update the Creating Components topic

Fixes: QDS-4110
Change-Id: I6fde0e36a8c74a0c9e1f56b9ce225444c921b74f
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
This commit is contained in:
Johanna Vanhatapio
2021-04-12 19:15:43 +03:00
parent fef8ebf46b
commit 39d4577d76
11 changed files with 77 additions and 63 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 43 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 29 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

@@ -76,8 +76,8 @@
\li Merge File with Template \li Merge File with Template
\li \l{Merging Files with Templates} \li \l{Merging Files with Templates}
\row \row
\li Move Component into Separate File \li Move Component Instances into Separate Files
\li \l{Moving Components into Separate Files} \li \l{Moving Component Instances into Separate Files}
\row \row
\li Add New Signal Handler \li Add New Signal Handler
\li \l{Adding Signal Handlers} \li \l{Adding Signal Handlers}

View File

@@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2020 The Qt Company Ltd. ** Copyright (C) 2021 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the Qt Creator documentation. ** This file is part of the Qt Creator documentation.
@@ -42,73 +42,84 @@
A \e component is a reusable building block for a UI. A \e component is a reusable building block for a UI.
\QDS comes with \e {preset components} that you can use in your project. \QDS comes with \e {preset components} that you can use in your UI by
These are similar to \e Symbols in Sketch or \e Prefab in Unity. creating instances of them.
The preset components are similar to \e Symbols in Sketch or \e Prefab in
Unity.
Some of the preset components represent simple shapes, text, or images, Some of the preset components represent simple shapes, text, or images,
while others represent complex UI controls with full functionality, such while others represent complex UI controls with full functionality, such
as spin boxes or sliders. as spin boxes or sliders. You can also add instances of preset
\l {Using 3D Components}{3D components} to your UIs.
You can modify the \e properties of the preset components and combine them To build your own components, you can modify the \e properties of the
to build your own components. component instances and combine them.
A component is specified within one file (with the file extension 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 \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 in \e Button.ui.qml. Typically, the visual appearance of a component
is defined in a \e {UI file} (ui.qml). is defined in a \e {UI file} (ui.qml). To create component files,
you can use \l{Creating Components from Scratch}{wizard templates}, or
\l{Moving Component Instances into Separate Files}
{move component instances into separate component files}.
The \l {Library} view \uicontrol Components tab lists the components that Select \l Library > \uicontrol Components to view the preset components that
have been added to your project. have been added to your project. If you cannot find the components you need,
add the relevant modules to your project, as described in
\l {Adding and Removing Modules}.
\image qmldesigner-qml-components.png "Components" \image qtquick-components-tab.png "Components in Library"
\note Use as few components as possible. To minimize the number of \note Use as few components as possible. To minimize the number of
components, use \l{Adding Property Aliases}{alias properties} and components, use \l{Adding Property Aliases}{alias properties} and
\l{Adding States}{states} to create the differences in your component \l{Adding States}{states} to create the differences in your component
instances. We recommend reusing components instead of duplicating them, instances. Using component instances instead of duplicating the components
so the components do not need to be processed as completely new component reduces the time needed to load and build the application, as well as the
types. This reduces the time needed to load and build the application, size of the application package.
as well as the size of the application package.
\section1 Adding Components to Designs \section1 Creating Component Instances
\image qmldesigner-editing-components.png "Editing components in Form Editor" \image qmldesigner-editing-components.png "Creating Component Instances"
\list 1 \list 1
\li Drag and drop components from \uicontrol Library (1) to \li Drag-and-drop components from \uicontrol Library (1) to
\uicontrol Navigator (2) or \uicontrol {Form Editor} (3). \uicontrol Navigator (2), \uicontrol {Form Editor} (3), or
\li Select components in \uicontrol Navigator to edit the \l {3D Editor} (4). This creates instances of the components in the
current component file.
\li Select component instances in \uicontrol Navigator to edit the
values of their properties in \uicontrol Properties. values of their properties in \uicontrol Properties.
\image qmldesigner-properties-view.png "Properties view" \image qmldesigner-properties-view.png "Properties view"
For more information, see \l {Specifying Component Properties}. For more information, see \l {Specifying Component Properties}.
\li To change the appearance and behavior of your components in ways \li To change the appearance and behavior of the component instances
that are not supported out of the box, you can define custom in ways that are not supported in \QDS by default, you can define
properties for your components in the \uicontrol Connections view, custom properties in \uicontrol {Connection View} >
\uicontrol Properties tab. \uicontrol {Properties}.
\image qmldesigner-dynamicprops.png "Connections view Properties tab" \image qmldesigner-dynamicprops.png "Connection View Properties tab"
For more information, see \l{Specifying Dynamic Properties}. For more information, see \l{Specifying Dynamic Properties}.
\li To enable users to interact with components, connect the components \li To enable users to interact with the component instances, connect
to signals in the \uicontrol Connections view. For example, you can the instances to signals in \uicontrol {Connection View} >
specify what happens when a component is clicked. \uicontrol Connections. For example, you can specify what happens
For more information, see \l{Connecting Components to Signals}. when a component instance is clicked. For more information, see
\image qmldesigner-connections.png "Connections view Connections tab" \l{Connecting Components to Signals}.
\li To dynamically change the behavior of an object when another object \image qmldesigner-connections.png "Connection View Connections tab"
changes, create bindings between components in the \li To dynamically change the behavior of a component instance when
\uicontrol {Connection View}, \uicontrol Bindings tab. another component instance changes, create bindings between them in
\uicontrol {Connection View} > \uicontrol Bindings.
For more information, see \l{Adding Bindings Between Properties}. For more information, see \l{Adding Bindings Between Properties}.
\image qmldesigner-bindings.png "Connections view Bindings tab" \image qmldesigner-bindings.png "Connection View Bindings tab"
\li Add states to apply sets of changes to the property values of one \li Add states to apply sets of changes to the property values of one
or several components in the \uicontrol States view. or several component instances in the \uicontrol States view.
For more information, see \l{Adding States}. For more information, see \l{Adding States}.
\li Animate component properties in the \uicontrol Timeline view. \li Animate the properties of component instances in the \uicontrol
For more information, see \l{Creating Animations}. Timeline view. For more information, see \l{Creating Animations}.
\endlist \endlist
\section1 Creating Your Own Components \section1 Creating Your Own Components
You can either use project wizard templates to create custom components and You can either use project wizard templates to create custom components and
controls or \l{Moving Components into Separate Files}{move subcomponents controls or move component instances into separate files to turn them into
into separate files} to make them reusable in other components. new components that you can create instances of. You can then use the
instances of the new components in other components.
\section2 Creating Components from Scratch \section2 Creating Components from Scratch
@@ -128,27 +139,30 @@
tab in the \uicontrol Library view only if the filename begins with tab in the \uicontrol Library view only if the filename begins with
a capital letter. a capital letter.
\li Click \uicontrol Design to open the component file (ui.qml] in \li Click \uicontrol Design to open the component file (ui.qml) in
\uicontrol {Form Editor}. \uicontrol {Form Editor}.
\li Drag and drop a component from \uicontrol Library to \li Drag-and-drop a component from \uicontrol Library to
\uicontrol Navigator or \uicontrol {Form Editor}. \uicontrol Navigator or \uicontrol {Form Editor}.
\li Edit component properties in \uicontrol Properties. \li Edit component properties in the \uicontrol Properties view.
\image qmldesigner-custom-component-properties.png \image qmldesigner-custom-component-properties.png
The available properties depend on the component type. You can The available properties depend on the component type. You can
\l{Specifying Dynamic Properties}{add properties for \l{Specifying Dynamic Properties}{add properties for
components} in the \uicontrol Properties tab of the components} in \uicontrol {Connection View} > \uicontrol Properties.
\uicontrol {Connection View}.
\li To change the appearance and behavior of the component instances
in ways that are not supported in \QDS by default, you can define
custom properties in \uicontrol {Connection View} >
\uicontrol {Properties}.
\endlist \endlist
The following sections contain more information about how to use The following sections contain more information about how to use
\uicontrol {Form Editor} to edit 2D content and \uicontrol {3D Editor} \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 to edit 3D scenes, as well as examples of how to create UI controls
using basic components: using instances of basic components:
\list \list
@@ -166,26 +180,26 @@
\include qtdesignstudio-components.qdocinc creating studio components \include qtdesignstudio-components.qdocinc creating studio components
\endif \endif
\section2 Moving Components into Separate Files \section2 Moving Component Instances into Separate Files
An alternative way of creating reusable components is to move them An alternative way of creating reusable components is to move component
into separate component files (.ui.qml). Right-click a component instances into separate component files (.ui.qml). Right-click a component
in \uicontrol Navigator or \uicontrol {Form Editor} and select instance in \uicontrol Navigator or \uicontrol {Form Editor}, and select
\uicontrol {Move Component into Separate File} in the context menu. \uicontrol {Move Component into Separate File} in the context menu.
\image qtcreator-move-component-into-separate-file.png \image qtcreator-move-component-into-separate-file.png
Give the new component a name and select whether properties are set for Give the new component a name, and select whether properties are set for
the new component or for the original one. the new component or for the original one.
When you select \uicontrol OK, a new component file is created and a When you select \uicontrol OK, a new component file is created and an
reference to the component is added to the code in the current component instance of the component is added to the code in the current component
file. The way things look in \uicontrol {Form Editor} does not change. file. The look of your UI in \uicontrol {Form Editor} does not change.
To open the new component file for editing the properties that you want 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 to change for all instances of the component, right-click the component,
and then select \uicontrol {Go into Component} in the context menu. For and then select \uicontrol {Go into Component} in the context menu. For
additional ways of opening subcomponents, see \l{Moving Within Components}. additional ways of opening base components, see \l{Moving Within Components}.
For an example of creating a reusable custom component, see For an example of creating a reusable custom component, see
\if defined(qtcreator) \if defined(qtcreator)
@@ -194,17 +208,17 @@
\l{Progress Bar}. \l{Progress Bar}.
\endif \endif
Custom components are listed in the \uicontrol {My Components} section Custom components are listed in \uicontrol Library > \uicontrol Components
of the \uicontrol Components tab in \uicontrol Library and you can use > \uicontrol {My Components}, and you can use instances of them to build
them to build more components. more components.
\include qtquick-mcu-support.qdocinc mcu qtquick components \include qtquick-mcu-support.qdocinc mcu qtquick components
\section1 Merging Files with Templates \section1 Merging Files with Templates
You can merge the current component file against an existing second 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 component file using the second file in a way similar to using a CSS
CSS stylesheet. stylesheet.
To use this experimental feature, right-click a component in the To use this experimental feature, right-click a component in the
\uicontrol Navigator or \uicontrol {Form Editor} view and select \uicontrol Navigator or \uicontrol {Form Editor} view and select

View File

@@ -78,7 +78,7 @@
\list \list
\li \l{Creating Components}{Library} \li \l{Creating Components}{Library}
\li \l{Component Types}{Preset Components} \li \l{Component Types}{Preset Components}
\li \l{Adding Components to Designs}{My Components} \li \l{Creating Component Instances}{My Components}
\endlist \endlist
\section1 Device \section1 Device