aboutsummaryrefslogtreecommitdiffstats
path: root/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties
diff options
context:
space:
mode:
Diffstat (limited to 'examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties')
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/People/Main.qml9
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.py69
2 files changed, 65 insertions, 13 deletions
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/People/Main.qml b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/People/Main.qml
index 795d63867..4fedadbc5 100644
--- a/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/People/Main.qml
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/People/Main.qml
@@ -2,21 +2,22 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import People
+import QtQuick // For QColor
BirthdayParty {
Boy {
name: "Robert Campbell"
- BirthdayParty.rsvp: "2009-07-01"
+ BirthdayParty.rsvp: Date.fromLocaleString(Qt.locale(), "2023-03-01", "yyyy-MM-dd")
}
Boy {
name: "Leo Hodges"
- shoe_size: 10
- BirthdayParty.rsvp: "2009-07-06"
+ shoe { size: 10; color: "black"; brand: "Reebok"; price: 59.95 }
+ BirthdayParty.rsvp: Date.fromLocaleString(Qt.locale(), "2023-03-03", "yyyy-MM-dd")
}
host: Boy {
name: "Jack Smith"
- shoe_size: 8
+ shoe { size: 8; color: "blue"; brand: "Puma"; price: 19.95 }
}
}
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.py b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.py
index 8deb7d0bf..db3b8d5bd 100644
--- a/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.py
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.py
@@ -3,6 +3,7 @@
from __future__ import annotations
from PySide6.QtCore import QObject, Property, Signal
+from PySide6.QtGui import QColor
from PySide6.QtQml import QmlAnonymous, QmlElement
# To be used on the @QmlElement decorator
@@ -12,14 +13,68 @@ QML_IMPORT_MAJOR_VERSION = 1
@QmlAnonymous
+class ShoeDescription(QObject):
+ brand_changed = Signal()
+ size_changed = Signal()
+ price_changed = Signal()
+ color_changed = Signal()
+
+ def __init__(self, parent=None):
+ super().__init__(parent)
+ self._brand = ''
+ self._size = 0
+ self._price = 0
+ self._color = QColor()
+
+ @Property(str, notify=brand_changed, final=True)
+ def brand(self):
+ return self._brand
+
+ @brand.setter
+ def brand(self, b):
+ if self._brand != b:
+ self._brand = b
+ self.brand_changed.emit()
+
+ @Property(int, notify=size_changed, final=True)
+ def size(self):
+ return self._size
+
+ @size.setter
+ def size(self, s):
+ if self._size != s:
+ self._size = s
+ self.size_changed.emit()
+
+ @Property(float, notify=price_changed, final=True)
+ def price(self):
+ return self._price
+
+ @price.setter
+ def price(self, p):
+ if self._price != p:
+ self._price = p
+ self.price_changed.emit()
+
+ @Property(QColor, notify=color_changed, final=True)
+ def color(self):
+ return self._color
+
+ @color.setter
+ def color(self, c):
+ if self._color != c:
+ self._color = c
+ self.color_changed.emit()
+
+
+@QmlAnonymous
class Person(QObject):
name_changed = Signal()
- shoe_size_changed = Signal()
def __init__(self, parent=None):
super().__init__(parent)
self._name = ''
- self._shoe_size = 0
+ self._shoe = ShoeDescription()
@Property(str, notify=name_changed, final=True)
def name(self):
@@ -31,13 +86,9 @@ class Person(QObject):
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
+ @Property(ShoeDescription, final=True)
+ def shoe(self):
+ return self._shoe
@QmlElement