aboutsummaryrefslogtreecommitdiffstats
path: root/examples/declarative/extending/chapter3-bindings
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2021-02-10 08:38:34 +0100
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2021-02-10 11:18:21 +0100
commita3a3cc0165ef700328a5078e01e503f5eb9fd2fa (patch)
treed8ebd789ee6fbdb8b5588f184a68b69d44a65540 /examples/declarative/extending/chapter3-bindings
parentae8f5327e21786690e021344cf2c122a02c89440 (diff)
Port QML examples to new property decorators
Task-number: PYSIDE-1019 Change-Id: I322c1d4d0f785b889d0676f7b9f292becd25e82f Reviewed-by: Christian Tismer <tismer@stackless.com>
Diffstat (limited to 'examples/declarative/extending/chapter3-bindings')
-rw-r--r--examples/declarative/extending/chapter3-bindings/bindings.py24
1 files changed, 14 insertions, 10 deletions
diff --git a/examples/declarative/extending/chapter3-bindings/bindings.py b/examples/declarative/extending/chapter3-bindings/bindings.py
index 2c1546927..474745652 100644
--- a/examples/declarative/extending/chapter3-bindings/bindings.py
+++ b/examples/declarative/extending/chapter3-bindings/bindings.py
@@ -50,6 +50,11 @@ from PySide6.QtQml import qmlRegisterType
from PySide6.QtQuick import QQuickPaintedItem, QQuickView
class PieChart (QQuickPaintedItem):
+
+ chartCleared = Signal()
+ nameChanged = Signal()
+ colorChanged = Signal()
+
def __init__(self, parent = None):
QQuickPaintedItem.__init__(self, parent)
self._name = u''
@@ -61,29 +66,28 @@ class PieChart (QQuickPaintedItem):
painter.setRenderHints(QPainter.Antialiasing, True)
painter.drawPie(self.boundingRect().adjusted(1,1,-1,-1), 90 * 16, 290 * 16)
- def getColor(self):
+ @Property(QColor, notify=colorChanged)
+ def color(self):
return self._color
- def setColor(self, value):
+ @color.setter
+ def color(self, value):
if value != self._color:
self._color = value
self.update()
self.colorChanged.emit()
- def getName(self):
+ @Property(str, notify=nameChanged)
+ def name(self):
return self._name
- def setName(self, value):
+ @name.setter
+ def name(self, value):
self._name = value
- colorChanged = Signal()
- color = Property(QColor, getColor, setColor, notify=colorChanged)
- name = Property(str, getName, setName)
- chartCleared = Signal()
-
@Slot() # This should be something like @Invokable
def clearChart(self):
- self.setColor(Qt.transparent)
+ self.color = Qt.transparent
self.update()
self.chartCleared.emit()