diff options
| author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-08-05 15:43:24 +0200 |
|---|---|---|
| committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2024-08-05 17:08:13 +0200 |
| commit | dec5b616f6ef215d415686e8ac3c0eeca6550ad5 (patch) | |
| tree | 925efa742142381faf804acc1d34ab646311b3b4 /sources/pyside6/doc/tutorials/qmlintegration | |
| parent | b32183d2cd5fbbd1ac6a53827edf5d40428855ff (diff) | |
Python-QML integration tutorial: Streamline Python code
In the emphasized lines, fix an offset introduced
by 50061290756323ff339bd0473e67117c8191d130.
Pick-to: 6.7
Task-number: PYSIDE-2833
Change-Id: I4ea1eb6b520179c0d425bdb74eaae7663ce89125
Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io>
Diffstat (limited to 'sources/pyside6/doc/tutorials/qmlintegration')
| -rw-r--r-- | sources/pyside6/doc/tutorials/qmlintegration/main.py | 33 | ||||
| -rw-r--r-- | sources/pyside6/doc/tutorials/qmlintegration/qmlintegration.rst | 6 |
2 files changed, 14 insertions, 25 deletions
diff --git a/sources/pyside6/doc/tutorials/qmlintegration/main.py b/sources/pyside6/doc/tutorials/qmlintegration/main.py index 6e7897acd..b6c35c562 100644 --- a/sources/pyside6/doc/tutorials/qmlintegration/main.py +++ b/sources/pyside6/doc/tutorials/qmlintegration/main.py @@ -10,7 +10,7 @@ from PySide6.QtGui import QGuiApplication from PySide6.QtQml import QQmlApplicationEngine, QmlElement from PySide6.QtQuickControls2 import QQuickStyle -import style_rc +import style_rc # noqa F401 # To be used on the @QmlElement decorator # (QML_IMPORT_MINOR_VERSION is optional) @@ -25,41 +25,28 @@ class Bridge(QObject): def getColor(self, s): if s.lower() == "red": return "#ef9a9a" - elif s.lower() == "green": + if s.lower() == "green": return "#a5d6a7" - elif s.lower() == "blue": + if s.lower() == "blue": return "#90caf9" - else: - return "white" + return "white" @Slot(float, result=int) def getSize(self, s): size = int(s * 34) - if size <= 0: - return 1 - else: - return size + return max(1, size) @Slot(str, result=bool) def getItalic(self, s): - if s.lower() == "italic": - return True - else: - return False + return s.lower() == "italic" @Slot(str, result=bool) def getBold(self, s): - if s.lower() == "bold": - return True - else: - return False + return s.lower() == "bold" @Slot(str, result=bool) def getUnderline(self, s): - if s.lower() == "underline": - return True - else: - return False + return s.lower() == "underline" if __name__ == '__main__': @@ -75,4 +62,6 @@ if __name__ == '__main__': if not engine.rootObjects(): sys.exit(-1) - sys.exit(app.exec()) + ex = app.exec() + del engine + sys.exit(ex) diff --git a/sources/pyside6/doc/tutorials/qmlintegration/qmlintegration.rst b/sources/pyside6/doc/tutorials/qmlintegration/qmlintegration.rst index ff6fe3e31..925684e26 100644 --- a/sources/pyside6/doc/tutorials/qmlintegration/qmlintegration.rst +++ b/sources/pyside6/doc/tutorials/qmlintegration/qmlintegration.rst @@ -29,7 +29,7 @@ application and PySide6 integration: .. literalinclude:: main.py :linenos: - :lines: 63-76 + :lines: 52-67 :emphasize-lines: 4,9 Notice that we only need a :code:`QQmlApplicationEngine` to @@ -40,8 +40,8 @@ application and PySide6 integration: .. literalinclude:: main.py :linenos: - :lines: 14-54 - :emphasize-lines: 3,4,7 + :lines: 14-49 + :emphasize-lines: 4,5,8 Notice that the registration happens thanks to the :code:`QmlElement` decorator, that underneath uses the reference to the :code:`Bridge` |
