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)
|
2020-06-11 10:41:24 +02:00
|
|
|
\previouspage studio-app-flows.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
|
2020-04-21 16:18:10 +02:00
|
|
|
\nextpage qtquick-form-editor.html
|
2011-12-14 15:07:05 +01:00
|
|
|
|
|
|
|
|
\title Creating Components
|
|
|
|
|
|
2013-03-13 11:39:36 +01:00
|
|
|
A \l{glossary-component}{component} provides a way of defining a new visual item
|
2011-12-14 15:07:05 +01:00
|
|
|
that you can re-use in other QML files. A component is like a black box; it
|
|
|
|
|
interacts with the outside world through properties, signals, and slots, and
|
|
|
|
|
is generally defined in its own QML file. You can import components to
|
2018-07-11 13:36:37 +02:00
|
|
|
applications.
|
|
|
|
|
|
2020-02-25 11:24:03 +01:00
|
|
|
The \uicontrol {Library} view lists the available QML types, UI
|
2020-02-20 16:32:01 +01:00
|
|
|
components, assets, and QML imports.
|
2018-07-11 13:36:37 +02:00
|
|
|
|
|
|
|
|
\image qmldesigner-qml-components.png "QML Components"
|
|
|
|
|
|
2020-05-07 09:24:14 +02:00
|
|
|
The \uicontrol {QML Types} tab displays the QML types grouped by category,
|
|
|
|
|
such as your own QML components, basic types, layouts, positioner types, and
|
|
|
|
|
views.
|
2018-07-11 13:36:37 +02:00
|
|
|
|
2020-10-01 16:48:17 +02:00
|
|
|
\section1 QML Imports
|
|
|
|
|
|
2018-07-11 13:36:37 +02:00
|
|
|
Sets of UI components with the look and feel of a particular mobile device
|
|
|
|
|
platform have been defined for Qt Quick 1. Since Qt 5.1, ready-made Qt
|
|
|
|
|
Quick Controls, Dialogs, and Layouts are available for creating user
|
|
|
|
|
interfaces using Qt Quick 2. The components and controls are based on
|
2020-05-07 09:24:14 +02:00
|
|
|
standard QML types. To view the components and controls in
|
2020-02-20 16:32:01 +01:00
|
|
|
\uicontrol {Library}, import the component sets in \uicontrol {QML Imports}.
|
2018-07-11 13:36:37 +02:00
|
|
|
|
|
|
|
|
The \uicontrol {Qt Quick Application} wizards for a particular platform add
|
|
|
|
|
the import statements automatically. You can remove import statements in
|
2020-04-22 16:03:39 +02:00
|
|
|
\uicontrol {QML Imports}.
|
2018-07-11 13:36:37 +02:00
|
|
|
|
2020-10-01 16:48:17 +02:00
|
|
|
\section1 Assets
|
|
|
|
|
|
2020-08-14 08:36:32 +02:00
|
|
|
\uicontrol {Assets} displays the images and other files that you import to
|
|
|
|
|
the project folder by selecting \uicontrol {Add New Assets}.
|
2018-07-11 13:36:37 +02:00
|
|
|
|
2020-10-01 16:48:17 +02:00
|
|
|
When you drag and drop assets from the tab to \uicontrol Navigator or
|
|
|
|
|
\uicontrol {Form Editor}, QML components with a suitable type are
|
|
|
|
|
automatically created for you. For example, when using graphical
|
|
|
|
|
assets to create components, the components will be of the Image type.
|
|
|
|
|
|
2018-07-11 13:36:37 +02:00
|
|
|
\section1 Adding Components to Designs
|
|
|
|
|
|
2020-05-07 09:24:14 +02:00
|
|
|
\image qmldesigner-editing-components.png "Editing QML components in Design mode"
|
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"
|
|
|
|
|
For more information, see \l {Specifying Item 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.
|
|
|
|
|
For more information, see \l{Connecting Objects to Signals}.
|
|
|
|
|
\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
|
|
|
|
|
\uicontrol Connections view, \uicontrol Bindings tab.
|
|
|
|
|
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
|
|
|
|
|
|
2020-10-01 16:48:17 +02:00
|
|
|
\section1 Component Types
|
|
|
|
|
|
|
|
|
|
The following sections describe the types of components that you can create
|
|
|
|
|
in the Design mode.
|
|
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
\li \l Shapes
|
2020-11-18 17:52:08 +01:00
|
|
|
\li \l Text
|
2020-11-06 15:44:50 +01:00
|
|
|
\li \l Images
|
2020-11-12 13:55:16 +01:00
|
|
|
\li \l {User Interaction Methods}
|
2020-11-03 15:18:06 +01:00
|
|
|
\li \l {Lists and Other Data Models}
|
2020-12-02 18:34:46 +01:00
|
|
|
\if defined(qtdesignstudio)
|
|
|
|
|
\li \l {2D Effects}
|
2020-12-11 12:57:07 +01:00
|
|
|
\li \l {Logic Helpers}
|
2020-12-02 18:34:46 +01:00
|
|
|
\endif
|
2020-10-01 16:48:17 +02:00
|
|
|
\endlist
|
|
|
|
|
|
2020-11-12 13:55:16 +01:00
|
|
|
\include qtquick-animation-types.qdocinc qtquick animation types
|
2018-07-11 13:36:37 +02:00
|
|
|
|
2020-11-19 11:38:45 +01:00
|
|
|
\include qtquick-mcu-support.qdocinc mcu qtquick components
|
|
|
|
|
|
2020-11-12 13:55:16 +01:00
|
|
|
\section1 Styling Controls
|
2018-07-11 13:36:37 +02:00
|
|
|
|
2020-11-12 13:55:16 +01:00
|
|
|
Qt Quick Controls provide lightweight QML types for creating performant
|
|
|
|
|
user interfaces for \l{glossary-device}{devices}. The controls can be
|
|
|
|
|
\l {Styling Qt Quick Controls}{styled}. The visual editor reads the
|
|
|
|
|
\c qtquickcontrols2.conf file that specifies the preferred style and some
|
|
|
|
|
style-specific arguments. To change the style, select another style from
|
|
|
|
|
the list on the toolbar. This enables you to check how your UI looks when
|
|
|
|
|
using the available styles.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2020-11-12 13:55:16 +01:00
|
|
|
\image qtquick-designer-style-list.png "Style menu on the toolbar"
|
2019-03-27 14:04:36 +01:00
|
|
|
|
2020-11-12 13:55:16 +01:00
|
|
|
For an example of defining your own style and using it in the Design mode,
|
|
|
|
|
see \l {Qt Quick Controls 2 - Flat Style}.
|
2020-08-11 17:02:49 +02:00
|
|
|
|
2020-11-12 13:55:16 +01:00
|
|
|
For more information about how to customize a particular control, see
|
|
|
|
|
\l{Customization Reference}.
|
2018-08-21 16:57:07 +02:00
|
|
|
|
2020-11-12 13:55:16 +01:00
|
|
|
\if defined(qtcreator)
|
2018-07-11 13:36:37 +02:00
|
|
|
\section1 History of Qt Quick Controls
|
2017-05-04 11:47:04 +02:00
|
|
|
|
|
|
|
|
In Qt 4, ready-made Qt Quick 1 Components were provided for creating
|
2019-04-16 11:15:09 +02:00
|
|
|
UIs with a native look and feel for a particular target platform.
|
2017-05-04 11:47:04 +02:00
|
|
|
In Qt 5.1, Qt Quick Controls, Dialogs, and Layouts were added for
|
|
|
|
|
creating classic desktop-style user interfaces using Qt Quick 2.1. The
|
|
|
|
|
Qt Quick Controls Styles could be used to customize Qt Quick Controls.
|
2013-05-08 17:20:20 +02:00
|
|
|
|
2016-09-30 14:23:05 +02:00
|
|
|
Since Qt 5.7, \l {Qt Quick Controls 2} replace Qt Quick Controls 1 and
|
2017-05-04 11:47:04 +02:00
|
|
|
Qt Labs Controls. They provide lightweight QML types for creating performant
|
2017-08-17 17:02:56 +02:00
|
|
|
user interfaces for \l{glossary-device}{devices}.
|
2016-03-22 16:14:09 +01:00
|
|
|
|
2017-05-04 11:47:04 +02:00
|
|
|
Qt Quick Controls 2 work in conjunction with Qt Quick and Qt Quick Layouts.
|
2015-10-26 16:40:58 +01:00
|
|
|
|
2013-05-08 17:20:20 +02:00
|
|
|
The \QC project wizards create Qt Quick applications that use Qt Quick
|
2017-05-04 11:47:04 +02:00
|
|
|
2 types or Qt Quick Controls 2 types.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2017-05-04 11:47:04 +02:00
|
|
|
Even if you use Qt Quick Controls 2, you can still write cross-platform
|
2011-12-14 15:07:05 +01:00
|
|
|
applications, by using different sets of QML files for each platform.
|
|
|
|
|
|
2017-05-04 11:47:04 +02:00
|
|
|
Some ready-made controls, such as a gauge, dial, status indicator, and
|
|
|
|
|
tumbler, are provided by the \l {Qt Quick Extras} module.
|
2020-11-12 13:55:16 +01:00
|
|
|
\endif
|
2017-05-04 11:47:04 +02:00
|
|
|
|
2018-06-25 17:46:23 +02:00
|
|
|
\section1 Creating Components in Design Mode
|
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
|
|
|
|
2020-05-07 09:24:14 +02:00
|
|
|
\note Components are listed in the \uicontrol {My QML Components}
|
|
|
|
|
tab in the \uicontrol Library view only if the filename begins with
|
|
|
|
|
a capital letter.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2018-06-25 17:46:23 +02:00
|
|
|
\li Click \uicontrol Design to open the .qml file in the Design mode.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2020-05-07 09:24:14 +02:00
|
|
|
\li Drag and drop a QML type 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
|
|
|
|
2020-05-07 09:24:14 +02:00
|
|
|
\li Edit its 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
|
|
|
|
|
|
|
|
|
|
The available properties depend on the QML type. You can
|
|
|
|
|
\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
|
2020-04-21 16:18:10 +02:00
|
|
|
\uicontrol {Form Editor} to edit 2D content, as well as examples of
|
|
|
|
|
how to create some common components using basic QML types:
|
2011-12-14 15:07:05 +01:00
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
|
2020-04-21 16:18:10 +02:00
|
|
|
\li \l{Editing 2D Content}
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
An alternative way of creating reusable components is to move them into
|
|
|
|
|
separate QML files. Right-click a component in the \uicontrol Navigator
|
|
|
|
|
or \uicontrol {Form Editor} view and select
|
|
|
|
|
\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.
|
|
|
|
|
|
|
|
|
|
For an example of creating a reusable custom component, see
|
|
|
|
|
\if defined(qtcreator)
|
|
|
|
|
\l{Creating a Mobile Application}.
|
|
|
|
|
\else
|
|
|
|
|
\l{Progress Bar}.
|
|
|
|
|
\endif
|
|
|
|
|
|
2011-12-14 15:07:05 +01:00
|
|
|
\section1 Moving Within Components
|
|
|
|
|
|
2020-11-25 10:34:18 +01:00
|
|
|
The QML files that specify components can contain instances of other
|
|
|
|
|
components specified in separate QML files. You can open the QML file
|
|
|
|
|
that specifies a component in different ways from different views:
|
|
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
\li In \uicontrol {Form Editor} or \uicontrol Navigator,
|
|
|
|
|
right-click an instance of a component and then select
|
|
|
|
|
\uicontrol {Go into Component} in the context-menu or
|
|
|
|
|
press \key F2.
|
|
|
|
|
\li In \uicontrol Properties, select \uicontrol {Edit Master Component}.
|
|
|
|
|
\endlist
|
|
|
|
|
|
|
|
|
|
The component hierarchy is displayed as a bread crumb path, where you can
|
|
|
|
|
click the component names to open the respective files. This enables you
|
|
|
|
|
to easily navigate back to the top level when you are done editing the
|
2020-05-07 09:24:14 +02:00
|
|
|
component.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2020-11-25 10:34:18 +01:00
|
|
|
\image qmldesigner-breadcrumbs.png "Component hierarchy"
|
2020-11-18 11:10:18 +01:00
|
|
|
|
|
|
|
|
\section1 Merging Files with Templates
|
|
|
|
|
|
|
|
|
|
You can merge the current QML file against an existing second QML file and
|
|
|
|
|
using the second QML file in a way similar to using a CSS stylesheet.
|
|
|
|
|
|
|
|
|
|
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
|
|
|
*/
|