aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/doc/extras/QtQml.QmlAttached.rst
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/doc/extras/QtQml.QmlAttached.rst')
-rw-r--r--sources/pyside6/doc/extras/QtQml.QmlAttached.rst35
1 files changed, 35 insertions, 0 deletions
diff --git a/sources/pyside6/doc/extras/QtQml.QmlAttached.rst b/sources/pyside6/doc/extras/QtQml.QmlAttached.rst
new file mode 100644
index 000000000..4331b03f9
--- /dev/null
+++ b/sources/pyside6/doc/extras/QtQml.QmlAttached.rst
@@ -0,0 +1,35 @@
+.. currentmodule:: PySide6.QtQml
+.. py:decorator:: QmlAttached
+
+This decorator declares that the enclosing type attaches the type passed as
+an attached property to other types. This takes effect if the type is exposed
+to QML using a ``QmlElement()`` or ``@QmlNamedElement()`` decorator.
+
+.. code-block:: python
+
+ QML_IMPORT_NAME = "com.library.name"
+ QML_IMPORT_MAJOR_VERSION = 1
+ QML_IMPORT_MINOR_VERSION = 0 # Optional
+
+ @QmlAnonymous
+ class LayoutAttached(QObject):
+ @Property(QMargins)
+ def margins(self):
+ ...
+
+ @QmlElement()
+ @QmlAttached(LayoutAttached)
+ class Layout(QObject):
+ ...
+
+Afterwards the class may be used in QML:
+
+.. code-block:: javascript
+
+ import com.library.name 1.0
+
+ Layout {
+ Widget {
+ Layout.margins: [2, 2, 2, 2]
+ }
+ }