Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
aboutsummaryrefslogtreecommitdiffstats
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/chapter1-basics
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/chapter1-basics')
-rw-r--r--examples/declarative/extending/chapter1-basics/basics.py22
1 files changed, 13 insertions, 9 deletions
diff --git a/examples/declarative/extending/chapter1-basics/basics.py b/examples/declarative/extending/chapter1-basics/basics.py
index c14669908..5e2614fc7 100644
--- a/examples/declarative/extending/chapter1-basics/basics.py
+++ b/examples/declarative/extending/chapter1-basics/basics.py
@@ -44,15 +44,19 @@
import os
import sys
-from PySide6.QtCore import Property, Signal, QUrl
+from PySide6.QtCore import Property, Signal, Qt, QUrl
from PySide6.QtGui import QGuiApplication, QPen, QPainter, QColor
from PySide6.QtQml import qmlRegisterType
from PySide6.QtQuick import QQuickPaintedItem, QQuickView
class PieChart (QQuickPaintedItem):
+
+ 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,22 +64,22 @@ 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
- nameChanged = Signal()
-
- color = Property(QColor, getColor, setColor)
- name = Property(str, getName, setName, notify=nameChanged)
if __name__ == '__main__':
app = QGuiApplication(sys.argv)