diff options
Diffstat (limited to 'examples/declarative')
3 files changed, 20 insertions, 19 deletions
diff --git a/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py b/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py index 024efbf16..9bd9f1e78 100644 --- a/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py +++ b/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py @@ -51,9 +51,10 @@ from utils import text_type from PySide2.QtCore import Property, QUrl from PySide2.QtGui import QGuiApplication, QPen, QPainter, QColor from PySide2.QtQml import qmlRegisterType -from PySide2.QtQuick import QQuickPaintedItem, QQuickView +from PySide2.QtQuick import QQuickPaintedItem, QQuickView, QQuickItem class PieSlice (QQuickPaintedItem): + def __init__(self, parent = None): QQuickPaintedItem.__init__(self, parent) self._color = QColor() @@ -68,14 +69,14 @@ class PieSlice (QQuickPaintedItem): def paint(self, painter): pen = QPen(self._color, 2) - painter.setPen(pen); - painter.setRenderHints(QPainter.Antialiasing, True); - painter.drawPie(self.boundingRect().adjusted(1,1,-1,-1), 90 * 16, 290 * 16); + painter.setPen(pen) + painter.setRenderHints(QPainter.Antialiasing, True) + painter.drawPie(self.boundingRect().adjusted(1,1,-1,-1), 90 * 16, 290 * 16) -class PieChart (QQuickPaintedItem): +class PieChart (QQuickItem): def __init__(self, parent = None): - QQuickPaintedItem.__init__(self, parent) - self._name = u'' + QQuickItem.__init__(self, parent) + self._name = None self._pieSlice = None def getName(self): diff --git a/examples/declarative/extending/chapter5-listproperties/listproperties.py b/examples/declarative/extending/chapter5-listproperties/listproperties.py index c06e11ca0..1aec72755 100644 --- a/examples/declarative/extending/chapter5-listproperties/listproperties.py +++ b/examples/declarative/extending/chapter5-listproperties/listproperties.py @@ -51,7 +51,7 @@ from utils import text_type from PySide2.QtCore import Property, QUrl from PySide2.QtGui import QGuiApplication, QPen, QPainter, QColor from PySide2.QtQml import qmlRegisterType, ListProperty -from PySide2.QtQuick import QQuickPaintedItem, QQuickView +from PySide2.QtQuick import QQuickPaintedItem, QQuickView, QQuickItem class PieSlice (QQuickPaintedItem): def __init__(self, parent = None): @@ -84,13 +84,13 @@ class PieSlice (QQuickPaintedItem): def paint(self, painter): pen = QPen(self._color, 2) - painter.setPen(pen); - painter.setRenderHints(QPainter.Antialiasing, True); - painter.drawPie(self.boundingRect().adjusted(1,1,-1,-1), self._fromAngle * 16, self._angleSpan * 16); + painter.setPen(pen) + painter.setRenderHints(QPainter.Antialiasing, True) + painter.drawPie(self.boundingRect().adjusted(1,1,-1,-1), self._fromAngle * 16, self._angleSpan * 16) -class PieChart (QQuickPaintedItem): +class PieChart (QQuickItem): def __init__(self, parent = None): - QQuickPaintedItem.__init__(self, parent) + QQuickItem.__init__(self, parent) self._name = u'' self._slices = [] @@ -111,8 +111,8 @@ class PieChart (QQuickPaintedItem): if __name__ == '__main__': app = QGuiApplication(sys.argv) - qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart'); - qmlRegisterType(PieSlice, "Charts", 1, 0, "PieSlice"); + qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart') + qmlRegisterType(PieSlice, "Charts", 1, 0, "PieSlice") view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) diff --git a/examples/declarative/usingmodel.py b/examples/declarative/usingmodel.py index 494647c10..4b4387117 100644 --- a/examples/declarative/usingmodel.py +++ b/examples/declarative/usingmodel.py @@ -44,9 +44,9 @@ from __future__ import print_function import os import sys -from PySide2.QtCore import QAbstractListModel, Qt, QUrl -from PySide2.QtGui import QGuiApplication import PySide2.QtQml +from PySide2.QtCore import QAbstractListModel, Qt, QUrl, QByteArray +from PySide2.QtGui import QGuiApplication from PySide2.QtQuick import QQuickView class PersonModel (QAbstractListModel): @@ -58,8 +58,8 @@ class PersonModel (QAbstractListModel): def roleNames(self): roles = { - PersonModel.MyRole : 'modelData', - Qt.DisplayRole : 'display' + PersonModel.MyRole : QByteArray(b'modelData'), + Qt.DisplayRole : QByteArray(b'display') } return roles |