aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/doc/extras/QtQml.QmlAttached.rst
blob: 60e006acb1c23c8f01152d852c90c9d90bf4a843 (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
36
37
38
PySide6.QtQml.QmlAttached
=========================

.. 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 :deco:`QmlElement` or :deco:`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]
             }
          }