diff options
Diffstat (limited to 'examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.py')
-rw-r--r-- | examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.py b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.py new file mode 100644 index 000000000..57e73e6f5 --- /dev/null +++ b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.py @@ -0,0 +1,52 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +from PySide6.QtCore import QObject, Property, Signal +from PySide6.QtQml import QmlElement, QmlUncreatable + +# To be used on the @QmlElement decorator +# (QML_IMPORT_MINOR_VERSION is optional) +QML_IMPORT_NAME = "People" +QML_IMPORT_MAJOR_VERSION = 1 + + +@QmlElement +@QmlUncreatable("Person is an abstract base class.") +class Person(QObject): + name_changed = Signal() + shoe_size_changed = Signal() + + def __init__(self, parent=None): + super().__init__(parent) + self._name = '' + self._shoe_size = 0 + + @Property(str, notify=name_changed, final=True) + def name(self): + return self._name + + @name.setter + def name(self, n): + if self._name != n: + self._name = n + self.name_changed.emit() + + @Property(int, notify=shoe_size_changed, final=True) + def shoe_size(self): + return self._shoe_size + + @shoe_size.setter + def shoe_size(self, s): + self._shoe_size = s + + +@QmlElement +class Boy(Person): + def __init__(self, parent=None): + super().__init__(parent) + + +@QmlElement +class Girl(Person): + def __init__(self, parent=None): + super().__init__(parent) |