1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
** Contact: Qt Software Information (qt-info@nokia.com)
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the either Technology Preview License Agreement or the
** Beta Release License Agreement.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain
** additional rights. These rights are described in the Nokia Qt LGPL
** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
** package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at qt-sales@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/
/*!
\page qml-integration.html
\title Integrating QML with existing Qt UI code
If you have existing Qt UI code which does not use QML, you can still
use QML in some ways without having to rewrite your UI.
\section1 Adding QML to a QWidget based UI
If you have an existing QWidget based UI you can simply write new custom
widgets in QML. To integrate them into your application you can create a
QmlView widget, and load the QML file into that. You'll then have a new widget
containing your declarative UI, and you can interact with it through the
QmlView interface. The one drawback of this approach is that QmlView is a lot
heavier than a QWidget in terms of memory consumption and initialization speed,
and so having large numbers of them may lead to performance degredation.
For a smooth transition from a QWidget based UI to a QML based UI, simply
rewrite your widgets in QML one at a time, using the above method. When
all of your widgets are written in QML you can rewrite your main widget in
QML, so as to load the other widgets in QML instead of using QmlViews. Then
you just load the main QML file on startup.
Keep in mind that QWidgets were designed for different sorts of UIs than QML
was, and so it is not always a good idea to switch. QWidgets are a better
choice if your UI is comprised of a small number of complex and static
elements, and QML is a better choice if your UI is comprised of a large number
of simple and dynamic elements.
\section1 Adding QML to a QGraphicsView based UI
If you have an existing QGraphicsView based UI you can create new items in QML,
and use QmlComponent to create QGraphicsObjects from the QML primitives. These
QGraphicsObjects can then be manually placed into your QGraphicsScene just like
any other.
\section1 Using existing QGraphicsWidgets in QML
Another way of integrating with a QGraphicsView based UI is to expose your
existing QGraphicsWidgets to QML, and constructing your scene in QML. Note that
this approach will not work with QGraphicsItems which are not QGraphicsWidgets,
and that this approach allows you to integrate new items written in QML
without using the above method.
As per the instructions in \l{Extending QML}, you can make custom C++ types
available in QML using a pair of macros. While this is normally only useful for
types that were designed for QML use, in conjunction with the
\l{GraphicsObjectContainer} element it works for QGraphicsWidgets which can be
controlled through properties. See the \l{GraphicsObjectContainer}
documentation for details about its use. This way you can write your UI using
QML, without having to rewrite any of your complex existing items.
*/
|