2014-10-28 15:18:01 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2019-01-23 15:51:12 +01:00
|
|
|
** Copyright (C) 2019 The Qt Company Ltd.
|
2016-01-15 14:51:16 +01:00
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-10-28 15:18:01 +01:00
|
|
|
**
|
2016-01-15 14:51:16 +01:00
|
|
|
** This file is part of the Qt Creator documentation.
|
2014-10-28 15:18:01 +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.
|
2014-10-28 15:18:01 +01:00
|
|
|
**
|
2016-01-15 14:51:16 +01:00
|
|
|
** GNU Free Documentation License Usage
|
2014-10-28 15:18:01 +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.
|
2014-10-28 15:18:01 +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.
|
|
|
|
|
// **********************************************************************
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
|
2018-07-11 13:53:28 +02:00
|
|
|
\contentspage index.html
|
2014-10-28 15:18:01 +01:00
|
|
|
\page creator-quick-ui-forms.html
|
2019-05-03 15:12:52 +02:00
|
|
|
\if defined(qtdesignstudio)
|
2019-05-13 13:37:31 +02:00
|
|
|
\previouspage qmldesigner-pathview-editor.html
|
2019-07-05 14:14:29 +02:00
|
|
|
\nextpage creator-live-preview.html
|
2018-08-10 16:15:05 +02:00
|
|
|
\else
|
2019-05-13 13:37:31 +02:00
|
|
|
\previouspage qtquick-iso-icon-browser.html
|
2019-05-03 15:12:52 +02:00
|
|
|
\nextpage quick-export-to-qml.html
|
2018-08-10 16:15:05 +02:00
|
|
|
\endif
|
2014-10-28 15:18:01 +01:00
|
|
|
|
|
|
|
|
\title Qt Quick UI Forms
|
|
|
|
|
|
2014-11-12 11:20:36 +01:00
|
|
|
You can use \QC wizards to create UI forms that have the filename extension
|
2014-10-28 15:18:01 +01:00
|
|
|
\e .ui.qml. The UI forms contain a purely declarative subset of the QML
|
2014-12-11 15:43:19 +01:00
|
|
|
language. It is recommended that you edit the forms in the \uicontrol Design mode.
|
2014-10-28 15:18:01 +01:00
|
|
|
\QC enforces the use of the supported QML features by displaying error
|
|
|
|
|
messages.
|
|
|
|
|
|
|
|
|
|
The following features are not supported:
|
|
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
\li JavaScript blocks
|
|
|
|
|
\li Other bindings than pure expressions
|
|
|
|
|
\li Signal handlers
|
|
|
|
|
\li States in other items than the root item
|
2016-11-28 12:35:05 +01:00
|
|
|
\li Root items that are not derived from \l QQuickItem or \l [QML]{Item}
|
2014-10-28 15:18:01 +01:00
|
|
|
\endlist
|
|
|
|
|
|
|
|
|
|
The following types are not supported:
|
|
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
\li Behavior
|
|
|
|
|
\li Binding
|
|
|
|
|
\li Canvas
|
|
|
|
|
\li Component
|
|
|
|
|
\li Shader Effect
|
|
|
|
|
\li Timer
|
|
|
|
|
\li Transform
|
|
|
|
|
\li Transition
|
|
|
|
|
\endlist
|
|
|
|
|
|
2019-01-23 15:51:12 +01:00
|
|
|
\section1 Supported Methods
|
|
|
|
|
|
|
|
|
|
\QC supports most JavaScript functions that are supported by the QML
|
|
|
|
|
engine, as well as a subset of Qt QML methods.
|
|
|
|
|
|
|
|
|
|
This section lists the functions that you can use in \e .ui.qml files.
|
|
|
|
|
|
|
|
|
|
\section2 JavaScript Functions
|
|
|
|
|
|
|
|
|
|
As a rule of thumb, \e {pure functions} are supported. They only depend on
|
|
|
|
|
and modify states of parameters that are within their scope, and therefore
|
|
|
|
|
always return the same results when given the same parameters. This makes
|
|
|
|
|
it possible to convert and reformat property bindings without breaking the
|
|
|
|
|
\e .ui.qml files.
|
|
|
|
|
|
|
|
|
|
The following JavaScript functions are supported:
|
|
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
\li \c charAt()
|
|
|
|
|
\li \c charCodeAt()
|
|
|
|
|
\li \c concat()
|
|
|
|
|
\li \c endsWith()
|
|
|
|
|
\li \c includes()
|
|
|
|
|
\li \c indexOf()
|
|
|
|
|
\li \c isFinite()
|
|
|
|
|
\li \c isNaN()
|
|
|
|
|
\li \c lastIndexOf()
|
|
|
|
|
\li \c substring()
|
|
|
|
|
\li \c toExponential()
|
|
|
|
|
\li \c toFixed()
|
|
|
|
|
\li \c toLocaleLowerCase()
|
|
|
|
|
\li \c toLocaleString
|
|
|
|
|
\li \c toLocaleUpperCase()
|
|
|
|
|
\li \c toLowerCase()
|
|
|
|
|
\li \c toPrecision()
|
|
|
|
|
\li \c toString()
|
|
|
|
|
\li \c toUpperCase()
|
|
|
|
|
\li \c valueOf()
|
|
|
|
|
\endlist
|
|
|
|
|
|
|
|
|
|
In addition, all functions of the \c Math and \c Date objects are supported.
|
|
|
|
|
|
|
|
|
|
For more information, see
|
|
|
|
|
\l{https://doc.qt.io/qt-5/qtqml-javascript-functionlist.html}
|
|
|
|
|
{List of JavaScript Objects and Functions}.
|
|
|
|
|
|
|
|
|
|
\section2 Qt QML Methods
|
|
|
|
|
|
|
|
|
|
\QC supports color methods, helper methods for creating objects of
|
|
|
|
|
specific data types, and translation methods.
|
|
|
|
|
|
|
|
|
|
The following color methods are supported:
|
|
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
\li \l{Qt::darker()}{Qt.darker()}
|
|
|
|
|
\li \l{Qt::hsla()}{Qt.hsla()}
|
|
|
|
|
\li \l{Qt::hsva()}{Qt.hsva()}
|
|
|
|
|
\li \l{Qt::lighter()}{Qt.lighter()}
|
|
|
|
|
\li \l{Qt::rgba()}{Qt.rgba()}
|
|
|
|
|
\li \l{Qt::tint()}{Qt.tint()}
|
|
|
|
|
\endlist
|
|
|
|
|
|
|
|
|
|
The following helper methods are supported:
|
|
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
\li \l{Qt::formatDate()}{Qt.formatDate()}
|
|
|
|
|
\li \l{Qt::formatDateTime()}{Qt.formatDateTime()}
|
|
|
|
|
\li \l{Qt::formatTime()}{Qt.formatTime()}
|
|
|
|
|
\li \l{Qt::matrix4x4()}{Qt.matrix4x4()}
|
|
|
|
|
\li \l{Qt::point()}{Qt.point()}
|
|
|
|
|
\li \l{Qt::quaternion()}{Qt.quaternion()}
|
|
|
|
|
\li \l{Qt::rect()}{Qt.rect()}
|
|
|
|
|
\li \l{Qt::size()}{Qt.size()}
|
|
|
|
|
\li \l{Qt::vector2d()}{Qt.vector2d()}
|
|
|
|
|
\li \l{Qt::vector3d()}{Qt.vector3d()}
|
|
|
|
|
\li \l{Qt::vector4d()}{Qt.vector4d()}
|
|
|
|
|
\endlist
|
|
|
|
|
|
|
|
|
|
The following translation methods are supported:
|
|
|
|
|
|
|
|
|
|
\list
|
|
|
|
|
\li \l{Qt::}{qsTr()}
|
|
|
|
|
\li \l{Qt::}{qsTranslate()}
|
|
|
|
|
\li \l{Qt::}{qsTranslateNoOp()}
|
|
|
|
|
\li \l{Qt::}{qsTrId()}
|
|
|
|
|
\li \l{Qt::}{qsTrIdNoOp()}
|
|
|
|
|
\li \l{Qt::}{qsTrNoOp()}
|
|
|
|
|
\endlist
|
|
|
|
|
|
|
|
|
|
For more information about using the methods, see
|
|
|
|
|
\l{https://doc.qt.io/qt-5/qml-qtqml-qt.html}{Qt QML Methods}.
|
|
|
|
|
|
2014-10-28 15:18:01 +01:00
|
|
|
\section1 Using Qt Quick UI Forms
|
|
|
|
|
|
2017-02-03 15:43:05 +01:00
|
|
|
You can edit the forms in the \uicontrol {Form Editor} and
|
|
|
|
|
\uicontrol {Text Editor} tabs in the \uicontrol Design mode. Items that are
|
|
|
|
|
supposed to be used in QML code have to be exported as properties:
|
2014-10-28 15:18:01 +01:00
|
|
|
|
|
|
|
|
\code
|
|
|
|
|
Item {
|
|
|
|
|
width: 640
|
|
|
|
|
height: 480
|
|
|
|
|
|
|
|
|
|
property alias button: button
|
|
|
|
|
|
|
|
|
|
Button {
|
|
|
|
|
anchors.centerIn: parent
|
|
|
|
|
id: button
|
|
|
|
|
text: qsTr("Press Me")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
|
|
The property alias exports the button to the QML code that uses the form.
|
2014-12-02 16:21:54 +01:00
|
|
|
You can use the
|
2016-05-03 13:49:23 +02:00
|
|
|
\inlineimage export_checked.png
|
2015-09-23 15:46:10 +02:00
|
|
|
(\uicontrol Export) button in the \uicontrol Navigator to export an item as
|
|
|
|
|
a property:
|
2014-10-28 15:18:01 +01:00
|
|
|
|
|
|
|
|
\image qmldesigner-export-item.png
|
|
|
|
|
|
|
|
|
|
In the QML file that uses the form, you can use the \c button property alias
|
|
|
|
|
to implement signal handlers, for example. In the following code snippet,
|
|
|
|
|
the UI form is called \e MainForm.ui.qml:
|
|
|
|
|
|
|
|
|
|
\code
|
|
|
|
|
MainForm {
|
|
|
|
|
anchors.fill: parent
|
|
|
|
|
button.onClicked: messageDialog.show(qsTr("Button pressed"))
|
|
|
|
|
}
|
|
|
|
|
\endcode
|
|
|
|
|
|
|
|
|
|
You can also assign properties or define behavior or transitions.
|
|
|
|
|
|
2015-11-05 11:11:30 +01:00
|
|
|
To move from the \uicontrol Design mode directly to the implementation of a
|
|
|
|
|
type in the .qml file, right-click the type in the \uicontrol Navigator and
|
|
|
|
|
select \uicontrol {Go to Implementation} in the context menu.
|
|
|
|
|
|
2014-10-28 15:18:01 +01:00
|
|
|
*/
|