2011-12-14 15:07:05 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2013-01-28 17:12:19 +01:00
|
|
|
** Copyright (c) 2013 Digia Plc and/or its subsidiary(-ies).
|
2012-10-02 09:12:39 +02:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-12-14 15:07:05 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator
|
2011-12-14 15:07:05 +01:00
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
** GNU Free Documentation License
|
|
|
|
|
**
|
|
|
|
|
** 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.
|
|
|
|
|
**
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
// **********************************************************************
|
|
|
|
|
// 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.
|
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
|
|
|
|
\contentspage index.html
|
|
|
|
|
\previouspage creator-using-qt-quick-designer.html
|
|
|
|
|
\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
|
|
|
|
|
|
2013-03-13 10:29:46 +01:00
|
|
|
\li \l{http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-borderimage.html}
|
2012-08-20 12:40:26 +02:00
|
|
|
{Border Image}
|
2011-12-14 15:07:05 +01:00
|
|
|
uses an image as a border or background.
|
|
|
|
|
|
2013-03-13 10:29:46 +01:00
|
|
|
\li \l{http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-image.html}{Image}
|
2011-12-14 15:07:05 +01:00
|
|
|
adds a bitmap to the scene. You can stretch and tile images.
|
|
|
|
|
|
2013-03-13 10:29:46 +01:00
|
|
|
\li \l{http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-item.html}{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.
|
|
|
|
|
|
2013-03-13 10:29:46 +01:00
|
|
|
\li \l{http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-rectangle.html}{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.
|
|
|
|
|
|
2013-03-13 10:29:46 +01:00
|
|
|
\li \l{http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-text.html}{Text}
|
2011-12-14 15:07:05 +01:00
|
|
|
adds formatted read-only text.
|
|
|
|
|
|
2013-03-13 10:29:46 +01:00
|
|
|
\li \l{http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-textedit.html}{Text Edit}
|
2011-12-14 15:07:05 +01:00
|
|
|
adds a single line of editable formatted text that can be validated.
|
|
|
|
|
|
2013-03-13 10:29:46 +01:00
|
|
|
\li \l{http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-textinput.html}{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-03-13 10:29:46 +01:00
|
|
|
\li \l{http://qt-project.org/doc/qt-5.0/qtwebkit/qml-qtwebkit3-webview.html}{Web View}
|
2011-12-14 15:07:05 +01:00
|
|
|
adds web content to a canvas.
|
2013-11-12 12:54:27 +01:00
|
|
|
\endomit
|
2011-12-14 15:07:05 +01:00
|
|
|
|
|
|
|
|
\endlist
|
|
|
|
|
|
2013-03-13 11:39:36 +01:00
|
|
|
QML types allow you to write cross-platform applications with custom look
|
2013-05-08 17:20:20 +02:00
|
|
|
and feel. You can also use ready-made Qt Quick Components (for Qt 4) to
|
|
|
|
|
create screens with a native look and feel for a particular target platform.
|
|
|
|
|
Since Qt 5.1, a set of Qt Quick Controls is available for creating classic
|
|
|
|
|
desktop-style user interfaces using Qt Quick 2.1.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2013-05-08 17:20:20 +02:00
|
|
|
You can install Qt Quick 1 Components as part of the Qt 4 SDK and the Qt
|
|
|
|
|
Quick Controls as part of Qt 5.1, or later.
|
|
|
|
|
|
|
|
|
|
The \QC project wizards create Qt Quick applications that use Qt Quick
|
|
|
|
|
Components or Controls.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
|
|
|
|
Even if you use the Qt Quick Components, you can still write cross-platform
|
|
|
|
|
applications, by using different sets of QML files for each platform.
|
|
|
|
|
|
|
|
|
|
\section1 Creating Components in Qt Quick Designer
|
|
|
|
|
|
|
|
|
|
\list 1
|
|
|
|
|
|
2013-11-12 12:52:18 +01:00
|
|
|
\li Select \gui File > \gui {New File or Project} >
|
|
|
|
|
\gui {Files and Classes} > \gui Qt > \gui {QML File (Qt Quick 1)} or
|
|
|
|
|
\gui {QML File (Qt Quick 2)} > \gui Choose to create a new .qml
|
|
|
|
|
file.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
|
|
|
|
\note Components are listed in the \gui {QML Components} section of
|
|
|
|
|
the \gui Library pane only if the filename begins with a capital
|
|
|
|
|
letter.
|
|
|
|
|
|
2013-02-06 08:50:23 +01:00
|
|
|
\li Click \gui Design to open the .qml file in \QMLD.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2013-03-13 11:39:36 +01:00
|
|
|
\li Drag and drop a QML type from the \gui Library pane to the editor.
|
2011-12-14 15:07:05 +01:00
|
|
|
|
2013-03-13 11:39:36 +01:00
|
|
|
\li Edit its properties in the \gui 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,
|
|
|
|
|
select \gui {Go into Component} or press \key F2. Click the component
|
|
|
|
|
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"
|
|
|
|
|
*/
|