aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.py
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-05-02 16:56:50 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2023-05-03 14:42:15 +0200
commit2388ac63d3784e59b416f993e123241cfb7f2ffa (patch)
treeef367674f06055ed1c63261a119ecc246f9c7fd7 /examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.py
parent42be729770eeb5d40802cfc697bddd744ba2623f (diff)
QML reference examples: Add notify signals and final attribute to properties
Task-number: PYSIDE-2206 Task-number: QTBUG-111033 Pick-to: 6.5 Change-Id: I0541a3bbb4e5696962802da7f91ab79682700124 Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.py')
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.py15
1 files changed, 10 insertions, 5 deletions
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.py b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.py
index 47dddc85d..764815175 100644
--- a/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.py
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.py
@@ -1,7 +1,7 @@
-# Copyright (C) 2022 The Qt Company Ltd.
+# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-from PySide6.QtCore import QObject, Property
+from PySide6.QtCore import QObject, Property, Signal
from PySide6.QtQml import QmlElement, ListProperty
from person import Person
@@ -15,19 +15,23 @@ 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)
+ @Property(Person, notify=host_changed, final=True)
def host(self):
return self._host
@host.setter
def host(self, h):
- self._host = h
+ if self._host != h:
+ self._host = h
+ self.host_changed.emit()
def guest(self, n):
return self._guests[n]
@@ -37,5 +41,6 @@ class BirthdayParty(QObject):
def appendGuest(self, guest):
self._guests.append(guest)
+ self.guests_changed.emit()
- guests = ListProperty(Person, appendGuest)
+ guests = ListProperty(Person, appendGuest, notify=guests_changed, final=True)