aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/doc/extras/QtQml.QmlAttached.rst
blob: 4331b03f9590401ea93102e209c2852cfe3e9235 (plain)
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
.. 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]
         }
      }