aboutsummaryrefslogtreecommitdiffstats
path: root/sources/pyside6/doc/quickstart.rst
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2024-08-07 15:15:12 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2024-08-08 12:25:10 +0200
commit0e9652d5542fccafdf8832ef5942b15040a1d8f2 (patch)
tree54bab26d51eace9eeaca39dbe6be0ab0220f027d /sources/pyside6/doc/quickstart.rst
parent838e93471e33ec683e711b6d97c8148d4f4a162c (diff)
Documentation: Rewrite 'Quick start' to use loadFromModule()
Pick-to: 6.7 Task-number: PYSIDE-2833 Change-Id: I757fe6884a11454aa10d80248e78008807099160 Reviewed-by: Shyamnath Premnadh <Shyamnath.Premnadh@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'sources/pyside6/doc/quickstart.rst')
-rw-r--r--sources/pyside6/doc/quickstart.rst27
1 files changed, 17 insertions, 10 deletions
diff --git a/sources/pyside6/doc/quickstart.rst b/sources/pyside6/doc/quickstart.rst
index 7e1a210f2..725b23355 100644
--- a/sources/pyside6/doc/quickstart.rst
+++ b/sources/pyside6/doc/quickstart.rst
@@ -174,9 +174,10 @@ To do the same using Qt Quick:
* **Declarative UI**
- The UI can be described in the QML language (assigned to a Python variable)::
+ The UI can be described in the QML language:
+
+ .. code-block:: javascript
- QML = """
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
@@ -210,30 +211,36 @@ To do the same using Qt Quick:
}
}
}
- """
- .. note:: Keep in mind ideally this content should go into
- a ``qml`` file, but for simplicity, we are using a string variable.
+ Put the this into a file named :code:`Main.qml` 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
* **Application execution**
Now, add a main function where you instantiate a :ref:`QQmlApplicationEngine` and
load the QML::
+ import sys
+ from PySide6.QtGui import QGuiApplication
+ from PySide6.QtQml import QQmlApplicationEngine
+
if __name__ == "__main__":
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
- engine.loadData(QML.encode('utf-8'))
+ engine.addImportPath(sys.path[0])
+ engine.loadFromModule("Main", "Main")
if not engine.rootObjects():
sys.exit(-1)
exit_code = app.exec()
del engine
sys.exit(exit_code)
-
- .. note:: This is a simplified example. Normally, the QML code should be in a separate
- :code:`.qml` file, which can be edited by design tools.
-
.. _faq-section:
Frequently Asked Questions