aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside2/doc/extras/QtQml.qmlRegisterUncreatableType.rst
blob: 0e73f3d971e9c6b46bbf9ad6f2d150c88a9f5557 (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
.. currentmodule:: PySide2.QtQml
.. _qmlRegisterUncreatableType:


qmlRegisterUncreatableType
**************************


.. py:function:: qmlRegisterUncreatableType(pytype: type, uri: str, versionMajor: int, versionMinor: int, qmlName: str, noCreationReason: str) -> int


   :param type pytype: Python class
   :param str uri: uri to use while importing the component in QML
   :param int versionMajor: major version
   :param int versionMinor: minor version
   :param str qmlName: name exposed to QML
   :param str noCreationReason: Error message shown when trying to create the QML type
   :return: int (the QML type id)

   This function registers the Python *type* in the QML system as an uncreatable type with the
   name *qmlName*, in the library imported from *uri* having the
   version number composed from *versionMajor* and *versionMinor*,
   showing *noCreationReason* as an error message when creating the type is attempted.

   For example, this registers a Python class 'MySliderItem' as a QML
   type named 'Slider' for version '1.0' of a module called
   'com.mycompany.qmlcomponents':

   ::
       qmlRegisterUncreatableType(MySliderItem, "com.mycompany.qmlcomponents", 1, 0, "Slider", "Slider cannot be created.")

   Note that it's perfectly reasonable for a library to register types
   to older versions than the actual version of the library.
   Indeed, it is normal for the new library to allow QML written to
   previous versions to continue to work, even if more advanced
   versions of some of its types are available.