diff options
author | Friedemann Kleint <[email protected]> | 2021-02-10 08:38:34 +0100 |
---|---|---|
committer | Friedemann Kleint <[email protected]> | 2021-02-10 11:18:21 +0100 |
commit | a3a3cc0165ef700328a5078e01e503f5eb9fd2fa (patch) | |
tree | d8ebd789ee6fbdb8b5588f184a68b69d44a65540 /examples/declarative/extending/chapter2-methods | |
parent | ae8f5327e21786690e021344cf2c122a02c89440 (diff) |
Port QML examples to new property decorators
Task-number: PYSIDE-1019
Change-Id: I322c1d4d0f785b889d0676f7b9f292becd25e82f
Reviewed-by: Christian Tismer <[email protected]>
Diffstat (limited to 'examples/declarative/extending/chapter2-methods')
-rw-r--r-- | examples/declarative/extending/chapter2-methods/methods.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/examples/declarative/extending/chapter2-methods/methods.py b/examples/declarative/extending/chapter2-methods/methods.py index b10cab324..8b9c94c62 100644 --- a/examples/declarative/extending/chapter2-methods/methods.py +++ b/examples/declarative/extending/chapter2-methods/methods.py @@ -44,15 +44,20 @@ import os import sys -from PySide6.QtCore import Property, Signal, Slot, QUrl, Qt +from PySide6.QtCore import Property, Signal, Slot, Qt, QUrl from PySide6.QtGui import QGuiApplication, QPen, QPainter, QColor from PySide6.QtQml import qmlRegisterType from PySide6.QtQuick import QQuickPaintedItem, QQuickView class PieChart (QQuickPaintedItem): + + chartCleared = Signal() + nameChanged = Signal() + def __init__(self, parent = None): QQuickPaintedItem.__init__(self, parent) self._name = u'' + self._color = QColor() def paint(self, painter): pen = QPen(self.color, 2) @@ -60,25 +65,25 @@ 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) + def color(self): return self._color - def setColor(self, value): + @color.setter + def color(self, value): self._color = value - 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 - color = Property(QColor, getColor, setColor) - 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() |