aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/doc/tutorials
diff options
context:
space:
mode:
Diffstat (limited to 'sources/pyside6/doc/tutorials')
-rw-r--r--sources/pyside6/doc/tutorials/qmlintegration/Main/Main.qml (renamed from sources/pyside6/doc/tutorials/qmlintegration/view.qml)0
-rw-r--r--sources/pyside6/doc/tutorials/qmlintegration/Main/qmldir2
-rw-r--r--sources/pyside6/doc/tutorials/qmlintegration/main.py11
-rw-r--r--sources/pyside6/doc/tutorials/qmlintegration/qmlintegration.rst32
4 files changed, 26 insertions, 19 deletions
diff --git a/sources/pyside6/doc/tutorials/qmlintegration/view.qml b/sources/pyside6/doc/tutorials/qmlintegration/Main/Main.qml
index 635603fac..635603fac 100644
--- a/sources/pyside6/doc/tutorials/qmlintegration/view.qml
+++ b/sources/pyside6/doc/tutorials/qmlintegration/Main/Main.qml
diff --git a/sources/pyside6/doc/tutorials/qmlintegration/Main/qmldir b/sources/pyside6/doc/tutorials/qmlintegration/Main/qmldir
new file mode 100644
index 000000000..8ad738e16
--- /dev/null
+++ b/sources/pyside6/doc/tutorials/qmlintegration/Main/qmldir
@@ -0,0 +1,2 @@
+module Main
+Main 254.0 Main.qml
diff --git a/sources/pyside6/doc/tutorials/qmlintegration/main.py b/sources/pyside6/doc/tutorials/qmlintegration/main.py
index b6c35c562..574e314de 100644
--- a/sources/pyside6/doc/tutorials/qmlintegration/main.py
+++ b/sources/pyside6/doc/tutorials/qmlintegration/main.py
@@ -3,14 +3,13 @@
from __future__ import annotations
import sys
-from pathlib import Path
from PySide6.QtCore import QObject, Slot
from PySide6.QtGui import QGuiApplication
from PySide6.QtQml import QQmlApplicationEngine, QmlElement
from PySide6.QtQuickControls2 import QQuickStyle
-import style_rc # noqa F401
+import rc_style # noqa F401
# To be used on the @QmlElement decorator
# (QML_IMPORT_MINOR_VERSION is optional)
@@ -53,11 +52,9 @@ if __name__ == '__main__':
app = QGuiApplication(sys.argv)
QQuickStyle.setStyle("Material")
engine = QQmlApplicationEngine()
-
- # Get the path of the current directory, and then add the name
- # of the QML file, to load it.
- qml_file = Path(__file__).parent / 'view.qml'
- engine.load(qml_file)
+ # Add the current directory to the import paths and load the main module.
+ engine.addImportPath(sys.path[0])
+ engine.loadFromModule("Main", "Main")
if not engine.rootObjects():
sys.exit(-1)
diff --git a/sources/pyside6/doc/tutorials/qmlintegration/qmlintegration.rst b/sources/pyside6/doc/tutorials/qmlintegration/qmlintegration.rst
index 925684e26..3d127529c 100644
--- a/sources/pyside6/doc/tutorials/qmlintegration/qmlintegration.rst
+++ b/sources/pyside6/doc/tutorials/qmlintegration/qmlintegration.rst
@@ -29,8 +29,8 @@ application and PySide6 integration:
.. literalinclude:: main.py
:linenos:
- :lines: 52-67
- :emphasize-lines: 4,9
+ :lines: 51-64
+ :emphasize-lines: 6,7
Notice that we only need a :code:`QQmlApplicationEngine` to
:code:`load` the QML file.
@@ -41,7 +41,7 @@ application and PySide6 integration:
.. literalinclude:: main.py
:linenos:
:lines: 14-49
- :emphasize-lines: 4,5,8
+ :emphasize-lines: 3,4,7
Notice that the registration happens thanks to the :code:`QmlElement`
decorator, that underneath uses the reference to the :code:`Bridge`
@@ -61,7 +61,7 @@ application and PySide6 integration:
This :code:`id` will help you to get a reference to the element
that was registered from Python.
- .. literalinclude:: view.qml
+ .. literalinclude:: Main/Main.qml
:linenos:
:lines: 45-55
:emphasize-lines: 6-8
@@ -75,13 +75,20 @@ application and PySide6 integration:
will return *False*, that is how we make sure only one is being
applied to the text.
+#. Put the file into into a directory named :code:`Main` along
+ with a file named :code:`qmldir` to describe a basic QML module:
+
+ .. code-block:: text
+
+ module Main
+ Main 254.0 Main.qml
+
#. Each slot verifies if the selected option contains the text associated
to the property:
.. literalinclude:: main.py
:linenos:
- :lines: 42-47
- :emphasize-lines: 4,6
+ :lines: 42-44
Returning *True* or *False* allows you to activate and deactivate
the properties of the QML UI elements.
@@ -91,7 +98,7 @@ application and PySide6 integration:
.. literalinclude:: main.py
:linenos:
- :lines: 34-39
+ :lines: 33-36
#. Now, for changing the look of our application, you have two options:
@@ -109,13 +116,13 @@ application and PySide6 integration:
.. literalinclude:: style.qrc
:linenos:
- Generate the *rc* file running, ``pyside6-rcc style.qrc -o style_rc.py``
+ Generate the *rc* file running, ``pyside6-rcc style.qrc -o rc_style.py``
And finally import it from your ``main.py`` script.
.. literalinclude:: main.py
:linenos:
- :lines: 4-12
- :emphasize-lines: 9
+ :lines: 5-12
+ :emphasize-lines: 8
You can read more about this configuration file
`here <https://doc.qt.io/qt-5/qtquickcontrols2-configuration.html>`_.
@@ -124,5 +131,6 @@ application and PySide6 integration:
.. image:: textproperties_material.png
-You can :download:`view.qml <view.qml>` and
-:download:`main.py <main.py>` to try this example.
+You can download :download:`Main.qml <Main/Main.qml>`,
+:download:`qmldir <Main/qmldir>` and :download:`main.py <main.py>`
+to try this example.