aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qml/referenceexamples/extended/doc/extended.rst
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2022-09-15 13:21:53 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2022-09-16 10:30:36 +0200
commitcf32b66adbfb489cd6e5d5c0bf3f741b59ba204c (patch)
tree44be69c9487f5d4db1092d061a555bd6001c1ab4 /examples/qml/referenceexamples/extended/doc/extended.rst
parentb20d6f6906f91f9df608d7800f4e27f7a7160abe (diff)
Move examples around
Change the directory structure to closer match that of Qt. Task-number: PYSIDE-841 Change-Id: I87aca346b6654aafe94dd1fb83c184c182ceb2e6 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'examples/qml/referenceexamples/extended/doc/extended.rst')
-rw-r--r--examples/qml/referenceexamples/extended/doc/extended.rst41
1 files changed, 41 insertions, 0 deletions
diff --git a/examples/qml/referenceexamples/extended/doc/extended.rst b/examples/qml/referenceexamples/extended/doc/extended.rst
new file mode 100644
index 000000000..745960535
--- /dev/null
+++ b/examples/qml/referenceexamples/extended/doc/extended.rst
@@ -0,0 +1,41 @@
+.. _qml-extension-objects-example:
+
+Extending QML - Extension Objects Example
+=========================================
+
+This example builds on the the :ref:`qml-adding-types-example`.
+
+Shows how to use QmlExtended decorator to provide an extension object to a
+QLineEdit without modifying or subclassing it.
+
+Firstly, the LineEditExtension class is registered with the QML system as an
+extension of QLineEdit. We declare a foreign type to do this as we cannot
+modify Qt's internal QLineEdit class.
+
+.. code-block:: python
+
+ @QmlNamedElement("QLineEdit")
+ @QmlExtended(LineEditExtension)
+ @QmlForeign(QLineEdit)
+ class LineEditForeign(QObject):
+
+
+Note the usage of ``QmlNamedElement()`` instead of ``QmlElement()``.
+``QmlElement()`` uses the name of the containing type by default,
+``LineEditExtension`` in this case. As the class being an extension class is
+an implementation detail, we choose the more natural name ``QLineEdit``
+instead.
+
+The QML engine then instantiates a QLineEdit.
+
+In QML, a property is set on the line edit that only exists in the
+``LineEditExtension`` class:
+
+.. code-block:: javascript
+
+ QLineEdit {
+ left_margin: 20
+ }
+
+The extension type performs calls on the ``QLineEdit`` that otherwise will not
+be accessible to the QML engine.