diff options
author | Friedemann Kleint <[email protected]> | 2022-01-20 17:33:10 +0100 |
---|---|---|
committer | Friedemann Kleint <[email protected]> | 2022-01-21 07:54:26 +0100 |
commit | d898e002380e2b8808592b6e0e05c689e1b37bd8 (patch) | |
tree | 91fbe2d3dda6bad336073dae9802a4568e37f1bf /examples | |
parent | 935ccfefad7f78d56d61d3791ecb0a8491f72052 (diff) |
Examples: Remove remaining qmlRegisterType()
Pick-to: 6.2
Task-number: PYSIDE-841
Change-Id: I2c3f9b22a3c1fdc6ddbdd7f08db38db613274cfd
Reviewed-by: Cristian Maureira-Fredes <[email protected]>
Diffstat (limited to 'examples')
9 files changed, 52 insertions, 21 deletions
diff --git a/examples/declarative/editingmodel/main.py b/examples/declarative/editingmodel/main.py index 6aee0d224..34fcadc40 100644 --- a/examples/declarative/editingmodel/main.py +++ b/examples/declarative/editingmodel/main.py @@ -43,13 +43,12 @@ from pathlib import Path from PySide6.QtCore import QUrl from PySide6.QtGui import QGuiApplication -from PySide6.QtQml import QQmlApplicationEngine, qmlRegisterType +from PySide6.QtQml import QQmlApplicationEngine from model import BaseModel if __name__ == "__main__": app = QGuiApplication(sys.argv) - qmlRegisterType(BaseModel, "BaseModel", 1, 0, "BaseModel") engine = QQmlApplicationEngine() qml_file = Path(__file__).parent / "main.qml" engine.load(QUrl.fromLocalFile(qml_file)) diff --git a/examples/declarative/editingmodel/model.py b/examples/declarative/editingmodel/model.py index 99736e714..ae9c59d33 100644 --- a/examples/declarative/editingmodel/model.py +++ b/examples/declarative/editingmodel/model.py @@ -42,8 +42,15 @@ from PySide6.QtCore import (QAbstractListModel, QByteArray, QModelIndex, Qt, Slot) from PySide6.QtGui import QColor +from PySide6.QtQml import QmlElement +# To be used on the @QmlElement decorator +# (QML_IMPORT_MINOR_VERSION is optional) +QML_IMPORT_NAME = "BaseModel" +QML_IMPORT_MAJOR_VERSION = 1 + +@QmlElement class BaseModel(QAbstractListModel): RatioRole = Qt.UserRole + 1 diff --git a/examples/declarative/extending/chapter1-basics/basics.py b/examples/declarative/extending/chapter1-basics/basics.py index 412b25cad..b05695800 100644 --- a/examples/declarative/extending/chapter1-basics/basics.py +++ b/examples/declarative/extending/chapter1-basics/basics.py @@ -47,10 +47,16 @@ import sys from PySide6.QtCore import Property, Signal, QUrl from PySide6.QtGui import QGuiApplication, QPen, QPainter, QColor -from PySide6.QtQml import qmlRegisterType +from PySide6.QtQml import QmlElement from PySide6.QtQuick import QQuickPaintedItem, QQuickView +# To be used on the @QmlElement decorator +# (QML_IMPORT_MINOR_VERSION is optional) +QML_IMPORT_NAME = "Charts" +QML_IMPORT_MAJOR_VERSION = 1 + +@QmlElement class PieChart (QQuickPaintedItem): nameChanged = Signal() @@ -86,8 +92,6 @@ class PieChart (QQuickPaintedItem): if __name__ == '__main__': app = QGuiApplication(sys.argv) - qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart') - view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) qml_file = os.fspath(Path(__file__).resolve().parent / 'app.qml') diff --git a/examples/declarative/extending/chapter2-methods/methods.py b/examples/declarative/extending/chapter2-methods/methods.py index c9e7be8f3..b068cd220 100644 --- a/examples/declarative/extending/chapter2-methods/methods.py +++ b/examples/declarative/extending/chapter2-methods/methods.py @@ -47,10 +47,16 @@ import sys from PySide6.QtCore import Property, Signal, Slot, Qt, QUrl from PySide6.QtGui import QGuiApplication, QPen, QPainter, QColor -from PySide6.QtQml import qmlRegisterType +from PySide6.QtQml import QmlElement from PySide6.QtQuick import QQuickPaintedItem, QQuickView +# To be used on the @QmlElement decorator +# (QML_IMPORT_MINOR_VERSION is optional) +QML_IMPORT_NAME = "Charts" +QML_IMPORT_MAJOR_VERSION = 1 + +@QmlElement class PieChart(QQuickPaintedItem): chartCleared = Signal() @@ -93,8 +99,6 @@ class PieChart(QQuickPaintedItem): if __name__ == '__main__': app = QGuiApplication(sys.argv) - qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart') - view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) qml_file = os.fspath(Path(__file__).resolve().parent / 'app.qml') diff --git a/examples/declarative/extending/chapter3-bindings/bindings.py b/examples/declarative/extending/chapter3-bindings/bindings.py index cacac78da..17394d6ea 100644 --- a/examples/declarative/extending/chapter3-bindings/bindings.py +++ b/examples/declarative/extending/chapter3-bindings/bindings.py @@ -47,10 +47,16 @@ import sys from PySide6.QtCore import Property, Signal, Slot, QUrl, Qt from PySide6.QtGui import QGuiApplication, QPen, QPainter, QColor -from PySide6.QtQml import qmlRegisterType +from PySide6.QtQml import QmlElement from PySide6.QtQuick import QQuickPaintedItem, QQuickView +# To be used on the @QmlElement decorator +# (QML_IMPORT_MINOR_VERSION is optional) +QML_IMPORT_NAME = "Charts" +QML_IMPORT_MAJOR_VERSION = 1 + +@QmlElement class PieChart (QQuickPaintedItem): chartCleared = Signal() @@ -97,8 +103,6 @@ class PieChart (QQuickPaintedItem): if __name__ == '__main__': app = QGuiApplication(sys.argv) - qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart') - view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) qml_file = os.fspath(Path(__file__).resolve().parent / 'app.qml') diff --git a/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py b/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py index a4a74fef4..ce8fd4294 100644 --- a/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py +++ b/examples/declarative/extending/chapter4-customPropertyTypes/customPropertyTypes.py @@ -47,10 +47,16 @@ import sys from PySide6.QtCore import Property, QUrl from PySide6.QtGui import QGuiApplication, QPen, QPainter, QColor -from PySide6.QtQml import qmlRegisterType +from PySide6.QtQml import QmlElement from PySide6.QtQuick import QQuickPaintedItem, QQuickView, QQuickItem +# To be used on the @QmlElement decorator +# (QML_IMPORT_MINOR_VERSION is optional) +QML_IMPORT_NAME = "Charts" +QML_IMPORT_MAJOR_VERSION = 1 + +@QmlElement class PieSlice (QQuickPaintedItem): def __init__(self, parent=None): @@ -72,6 +78,7 @@ class PieSlice (QQuickPaintedItem): painter.drawPie(self.boundingRect().adjusted(1, 1, -1, -1), 90 * 16, 290 * 16) +@QmlElement class PieChart (QQuickItem): def __init__(self, parent=None): QQuickItem.__init__(self, parent) @@ -99,9 +106,6 @@ class PieChart (QQuickItem): if __name__ == '__main__': app = QGuiApplication(sys.argv) - qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart') - qmlRegisterType(PieSlice, "Charts", 1, 0, "PieSlice") - view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) qml_file = os.fspath(Path(__file__).resolve().parent / 'app.qml') diff --git a/examples/declarative/extending/chapter5-listproperties/listproperties.py b/examples/declarative/extending/chapter5-listproperties/listproperties.py index eeaba0858..8ea36c11c 100644 --- a/examples/declarative/extending/chapter5-listproperties/listproperties.py +++ b/examples/declarative/extending/chapter5-listproperties/listproperties.py @@ -47,10 +47,16 @@ import sys from PySide6.QtCore import Property, QUrl from PySide6.QtGui import QGuiApplication, QPen, QPainter, QColor -from PySide6.QtQml import qmlRegisterType, ListProperty +from PySide6.QtQml import QmlElement, ListProperty from PySide6.QtQuick import QQuickPaintedItem, QQuickView, QQuickItem +# To be used on the @QmlElement decorator +# (QML_IMPORT_MINOR_VERSION is optional) +QML_IMPORT_NAME = "Charts" +QML_IMPORT_MAJOR_VERSION = 1 + +@QmlElement class PieSlice (QQuickPaintedItem): def __init__(self, parent=None): QQuickPaintedItem.__init__(self, parent) @@ -89,6 +95,7 @@ class PieSlice (QQuickPaintedItem): painter.drawPie(self.boundingRect().adjusted(1, 1, -1, -1), self._fromAngle * 16, self._angleSpan * 16) +@QmlElement class PieChart (QQuickItem): def __init__(self, parent=None): QQuickItem.__init__(self, parent) @@ -113,9 +120,6 @@ class PieChart (QQuickItem): if __name__ == '__main__': app = QGuiApplication(sys.argv) - qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart') - qmlRegisterType(PieSlice, "Charts", 1, 0, "PieSlice") - view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) qml_file = os.fspath(Path(__file__).resolve().parent / 'app.qml') diff --git a/examples/declarative/openglunderqml/main.py b/examples/declarative/openglunderqml/main.py index 44ee10834..2da00fd6b 100644 --- a/examples/declarative/openglunderqml/main.py +++ b/examples/declarative/openglunderqml/main.py @@ -43,7 +43,6 @@ from pathlib import Path from PySide6.QtCore import QUrl from PySide6.QtGui import QGuiApplication -from PySide6.QtQml import qmlRegisterType from PySide6.QtQuick import QQuickView, QQuickWindow, QSGRendererInterface from squircle import Squircle @@ -52,7 +51,6 @@ if __name__ == "__main__": app = QGuiApplication(sys.argv) QQuickWindow.setGraphicsApi(QSGRendererInterface.OpenGL) - qmlRegisterType(Squircle, "OpenGLUnderQML", 1, 0, "Squircle") view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) diff --git a/examples/declarative/openglunderqml/squircle.py b/examples/declarative/openglunderqml/squircle.py index 3e600121b..4ae21661e 100644 --- a/examples/declarative/openglunderqml/squircle.py +++ b/examples/declarative/openglunderqml/squircle.py @@ -39,10 +39,16 @@ ############################################################################# from PySide6.QtCore import Property, QRunnable, Qt, Signal, Slot +from PySide6.QtQml import QmlElement from PySide6.QtQuick import QQuickItem, QQuickWindow from squirclerenderer import SquircleRenderer +# To be used on the @QmlElement decorator +# (QML_IMPORT_MINOR_VERSION is optional) +QML_IMPORT_NAME = "OpenGLUnderQML" +QML_IMPORT_MAJOR_VERSION = 1 + class CleanupJob(QRunnable): def __init__(self, renderer): @@ -53,6 +59,7 @@ class CleanupJob(QRunnable): del self._renderer +@QmlElement class Squircle(QQuickItem): tChanged = Signal() |