aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/doc/extras/QtQml.QmlNamedElement.rst
blob: 1ce8bd796f1ae17313813fefffb4ce8eafd59a13 (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
.. currentmodule:: PySide6.QtQml
.. py:decorator:: QmlNamedElement

    This decorator registers a class it is attached to for use in QML under
    a name different from the class name, using global variables to specify
    the import name and version.

    .. code-block:: python

        QML_IMPORT_NAME = "com.library.name"
        QML_IMPORT_MAJOR_VERSION = 1
        QML_IMPORT_MINOR_VERSION = 0 # Optional

        @QmlNamedElement("ClassForQml")
        class ClassWithSomeName(QObject):
              ...

    Afterwards the class may be used in QML:

    .. code-block:: javascript

        import com.library.name 1.0

        ClassForQml {
           // ...
        }