aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.py
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-05-02 10:41:54 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2023-05-10 00:30:02 +0200
commit58c304ca83d5fc66707cddc0998b2b63b1148508 (patch)
tree5d331d28c5d8d53667b62e1012f6a99015503562 /examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.py
parent9b791c5d8997a4593977c247de458cc45ea2049d (diff)
QML reference examples: Add the add advanced1-Base-project
Task-number: PYSIDE-2206 Task-number: QTBUG-111033 Pick-to: 6.5 Change-Id: I8b162f2f5cb6e7099c74e751bcdf95dea5d7d118 Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.py')
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.py b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.py
new file mode 100644
index 000000000..764815175
--- /dev/null
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced1-Base-project/birthdayparty.py
@@ -0,0 +1,46 @@
+# Copyright (C) 2023 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, ListProperty
+
+from person import Person
+
+
+# To be used on the @QmlElement decorator
+# (QML_IMPORT_MINOR_VERSION is optional)
+QML_IMPORT_NAME = "People"
+QML_IMPORT_MAJOR_VERSION = 1
+
+
+@QmlElement
+class BirthdayParty(QObject):
+ host_changed = Signal()
+ guests_changed = Signal()
+
+ def __init__(self, parent=None):
+ super().__init__(parent)
+ self._host = None
+ self._guests = []
+
+ @Property(Person, notify=host_changed, final=True)
+ def host(self):
+ return self._host
+
+ @host.setter
+ def host(self, h):
+ if self._host != h:
+ self._host = h
+ self.host_changed.emit()
+
+ def guest(self, n):
+ return self._guests[n]
+
+ def guestCount(self):
+ return len(self._guests)
+
+ def appendGuest(self, guest):
+ self._guests.append(guest)
+ self.guests_changed.emit()
+
+ guests = ListProperty(Person, appendGuest, notify=guests_changed, final=True)