diff options
author | Alan Alpert <alan.alpert@nokia.com> | 2010-01-05 17:47:32 (GMT) |
---|---|---|
committer | Alan Alpert <alan.alpert@nokia.com> | 2010-01-05 17:47:32 (GMT) |
commit | 51b7c1eff019b73a5eb47c437be37606e4e185bf (patch) | |
tree | e4777c505f0adef76ff64ab36dc99a72581852e0 /doc/src/declarative/integrating.qdoc | |
parent | 03a6b8a393aa94203b872a806d04f331d6162603 (diff) | |
download | Qt-51b7c1eff019b73a5eb47c437be37606e4e185bf.zip Qt-51b7c1eff019b73a5eb47c437be37606e4e185bf.tar.gz Qt-51b7c1eff019b73a5eb47c437be37606e4e185bf.tar.bz2 |
Improve documentation
Extend documentation on dynamically created objects and on integrating
with existing applications. And make those pages more discoverable.
Diffstat (limited to 'doc/src/declarative/integrating.qdoc')
-rw-r--r-- | doc/src/declarative/integrating.qdoc | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/doc/src/declarative/integrating.qdoc b/doc/src/declarative/integrating.qdoc index fd3b9f7..d93a6ff 100644 --- a/doc/src/declarative/integrating.qdoc +++ b/doc/src/declarative/integrating.qdoc @@ -43,10 +43,10 @@ \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. +If you have existing Qt UI code which does not use QML you can still +add QML to your UI, without having to rewrite it. -\section1 Adding QML to a QWidget based UI +\section1 Adding QML to a \l{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 @@ -68,10 +68,21 @@ 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. +If you have an existing Graphics View based UI you can create new items in QML, +and use \l{QmlComponent} to create \l{QGraphicsObject}s from the QML files. These +\l{QGraphicsObject}s can then be placed into your \l{QGraphicsScene} using \l{QGraphicsScene::addItem} +or by reparenting them to an item already in the \l{QGraphicsScene}. + +Example, for local QML files: + +\code +QGraphicsScene* scene = new QGraphicsScene; +QmlEngine *engine = new QmlEngine; +QmlComponent component(engine, QUrl::fromLocalFile(filename)); +QGraphicsObject *object = + qobject_cast<QGraphicsObject *>(component.create()); +scene->addItem(object); +\endcode \section1 Using existing QGraphicsWidgets in QML Another way of integrating with a QGraphicsView based UI is to expose your @@ -80,11 +91,14 @@ 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 +You can make custom C++ types +available in QML using the pair of macros listed in \l{Extending QML}. +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. +\l{GraphicsObjectContainer} element QGraphicsWidget subclasses can also be +used effectively (if they were designed, like QGraphicsWidget, to be controllable through Qt's property system). +This way you can write your UI using QML, without having to rewrite your existing items. + +For details on implementing this approach see \l{Extending QML} page for details on exposing your C++ types, +and the \l{GraphicsObjectContainer} documentation for details about using it to wrap QGraphicsWidgets. */ |