2011-12-14 15:07:05 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:51:16 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** 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.
|
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
2014-03-17 12:18:12 +01:00
|
|
|
\contentspage {Qt Creator Manual}
|
2015-11-19 16:29:31 +01:00
|
|
|
\previouspage qmldesigner-connections.html
|
2011-12-14 15:07:05 +01:00
|
|
|
\page quick-components.html
|
|
|
|
|
\nextpage quick-buttons.html
|
|
|
|
|
|
|
|
|
|
\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
|
|
|
|
|
screens and applications.
|
|
|
|
|
|
2013-03-13 11:39:36 +01:00
|
|
|
You can use the following QML types to create components:
|
2011-12-14 15:07:05 +01:00
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
|
2016-11-28 12:35:05 +01:00
|
|
|
\li \l [QML]{BorderImage}{Border Image} uses an image as a border or background.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2016-11-28 12:35:05 +01:00
|
|
|
\li \l [QML]{Image}
|
2011-12-14 15:07:05 +01:00
|
|
|
adds a bitmap to the scene. You can stretch and tile images.
|
|
|
|
|
|
2016-11-28 12:35:05 +01:00
|
|
|
\li \l [QML]{Item}
|
2013-03-13 11:39:36 +01:00
|
|
|
is the most basic of all visual types in QML. Even though it has no
|
2011-12-14 15:07:05 +01:00
|
|
|
visual appearance, it defines all the properties that are common
|
2013-03-13 11:39:36 +01:00
|
|
|
across visual types, such as the x and y position, width and height,
|
2011-12-14 15:07:05 +01:00
|
|
|
anchoring, and key handling.
|
|
|
|
|
|
2016-11-28 12:35:05 +01:00
|
|
|
\li \l [QML]{Rectangle}
|
2011-12-14 15:07:05 +01:00
|
|
|
adds a rectangle that is painted with a solid fill color and an
|
|
|
|
|
optional border. You can also use the radius property to create
|
|
|
|
|
rounded rectangles.
|
|
|
|
|
|
2016-11-28 12:35:05 +01:00
|
|
|
\li \l [QML]{Text} adds formatted read-only text.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2016-11-28 12:35:05 +01:00
|
|
|
\li \l [QML]{TextEdit}{Text Edit}
|
2011-12-14 15:07:05 +01:00
|
|
|
adds a single line of editable formatted text that can be validated.
|
|
|
|
|
|
2016-11-28 12:35:05 +01:00
|
|
|
\li \l [QML]{TextInput}{Text Input}
|
2011-12-14 15:07:05 +01:00
|
|
|
adds a single line of editable plain text that can be validated.
|
|
|
|
|
|
2013-11-12 12:54:27 +01:00
|
|
|
\omit
|
2013-11-25 17:37:19 +01:00
|
|
|
\li \l{WebView} adds web content to a canvas.
|
2013-11-12 12:54:27 +01:00
|
|
|
\endomit
|
2011-12-14 15:07:05 +01:00
|
|
|
|
|
|
|
|
\endlist
|
|
|
|
|
|
2017-05-04 11:47:04 +02:00
|
|
|
\section1 Using Qt Quick Controls
|
|
|
|
|
|
|
|
|
|
In Qt 4, ready-made Qt Quick 1 Components were provided for creating
|
2014-07-28 16:14:32 +02:00
|
|
|
screens 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 achieve improved efficiency by employing a simplified
|
|
|
|
|
\l {Styling Qt Quick Controls 2}{styling architecture} when compared to
|
|
|
|
|
Qt Quick Controls, on which the module is based. \QMLD 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.
|
|
|
|
|
|
2017-05-05 14:28:08 +02:00
|
|
|
For an example of defining your own style and using it in \QMLD, see
|
|
|
|
|
\l {Qt Quick Controls 2 - Flat Style}.
|
|
|
|
|
|
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.
|
|
|
|
|
|
2011-12-14 15:07:05 +01:00
|
|
|
\section1 Creating Components in Qt Quick Designer
|
|
|
|
|
|
|
|
|
|
\list 1
|
|
|
|
|
|
2014-12-11 15:43:19 +01:00
|
|
|
\li Select \uicontrol File > \uicontrol {New File or Project} >
|
2016-07-29 13:08:51 +02:00
|
|
|
\uicontrol {Files and Classes} > \uicontrol Qt >
|
2014-12-11 15:43:19 +01:00
|
|
|
\uicontrol {QML File (Qt Quick 2)} > \uicontrol Choose to create a new .qml
|
2013-11-12 12:52:18 +01:00
|
|
|
file.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2014-12-11 15:43:19 +01:00
|
|
|
\note Components are listed in the \uicontrol {QML Components} section of
|
|
|
|
|
the \uicontrol Library only if the filename begins with a capital
|
2011-12-14 15:07:05 +01:00
|
|
|
letter.
|
|
|
|
|
|
2014-12-11 15:43:19 +01:00
|
|
|
\li Click \uicontrol Design to open the .qml file in \QMLD.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2017-02-03 15:43:05 +01:00
|
|
|
\li Drag and drop a QML type from the \uicontrol Library to the
|
|
|
|
|
\uicontrol Navigator or \uicontrol {Form Editor}.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2014-12-11 15:43:19 +01:00
|
|
|
\li Edit its properties in the \uicontrol Properties pane.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2013-03-13 11:39:36 +01:00
|
|
|
The available properties depend on the QML type.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
|
|
|
|
\endlist
|
|
|
|
|
|
|
|
|
|
The following sections contain examples of how to create some common
|
|
|
|
|
components:
|
|
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
\section1 Moving Within Components
|
|
|
|
|
|
|
|
|
|
Components can consist of several other components. To view the component
|
|
|
|
|
hierarchy as a bread crumb path when you edit a component on the canvas,
|
2014-12-11 15:43:19 +01:00
|
|
|
select \uicontrol {Go into Component} or press \key F2. Click the component
|
2011-12-14 15:07:05 +01:00
|
|
|
names in the path to navigate to them. You can easily navigate back to the
|
|
|
|
|
top level when you are done editing the component.
|
|
|
|
|
|
|
|
|
|
\image qmldesigner-breadcrumbs.png "Go into Component command"
|
|
|
|
|
*/
|