aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/qml/signals/pytoqml1/main.py32
-rw-r--r--examples/qml/signals/pytoqml1/pytoqml1.pyproject3
-rw-r--r--examples/qml/signals/pytoqml1/view.qml36
-rw-r--r--examples/qml/signals/pytoqml2/main.py55
-rw-r--r--examples/qml/signals/pytoqml2/pytoqml2.pyproject3
-rw-r--r--examples/qml/signals/pytoqml2/view.qml30
-rw-r--r--examples/qml/signals/qmltopy1/doc/qmltopy1.rst13
-rw-r--r--examples/qml/signals/qmltopy2/doc/qmltopy2.rst12
-rw-r--r--examples/qml/signals/qmltopy3/doc/qmltopy3.rst10
-rw-r--r--examples/qml/signals/qmltopy4/doc/qmltopy4.rst11
10 files changed, 46 insertions, 159 deletions
diff --git a/examples/qml/signals/pytoqml1/main.py b/examples/qml/signals/pytoqml1/main.py
deleted file mode 100644
index 65806ac78..000000000
--- a/examples/qml/signals/pytoqml1/main.py
+++ /dev/null
@@ -1,32 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-from __future__ import annotations
-
-import os
-from pathlib import Path
-import sys
-from PySide6.QtCore import QTimer, QUrl
-from PySide6.QtGui import QGuiApplication
-from PySide6.QtQuick import QQuickView
-
-if __name__ == '__main__':
- app = QGuiApplication(sys.argv)
-
- timer = QTimer()
- timer.start(2000)
-
- view = QQuickView()
- qml_file = os.fspath(Path(__file__).resolve().parent / 'view.qml')
- view.setSource(QUrl.fromLocalFile(qml_file))
- if view.status() == QQuickView.Status.Error:
- sys.exit(-1)
- root = view.rootObject()
-
- timer.timeout.connect(root.updateRotater)
-
- view.show()
- res = app.exec()
- # Deleting the view before it goes out of scope is required to make sure all child QML instances
- # are destroyed in the correct order.
- del view
- sys.exit(res)
diff --git a/examples/qml/signals/pytoqml1/pytoqml1.pyproject b/examples/qml/signals/pytoqml1/pytoqml1.pyproject
deleted file mode 100644
index e6f087cce..000000000
--- a/examples/qml/signals/pytoqml1/pytoqml1.pyproject
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "files": ["main.py", "view.qml"]
-}
diff --git a/examples/qml/signals/pytoqml1/view.qml b/examples/qml/signals/pytoqml1/view.qml
deleted file mode 100644
index af2d966be..000000000
--- a/examples/qml/signals/pytoqml1/view.qml
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-import QtQuick
-
-Rectangle {
- id: page
-
- function updateRotater() {
- rotater.angle = rotater.angle + 45
- }
-
- width: 500; height: 200
- color: "lightgray"
-
- Rectangle {
- id: rotater
- property real angle : 0
- x: 240
- width: 100; height: 10
- color: "black"
- y: 95
-
- transform: Rotation {
- origin.x: 10; origin.y: 5
- angle: rotater.angle
- Behavior on angle {
- SpringAnimation {
- spring: 1.4
- damping: .05
- }
- }
- }
- }
-
-}
diff --git a/examples/qml/signals/pytoqml2/main.py b/examples/qml/signals/pytoqml2/main.py
deleted file mode 100644
index cb8844621..000000000
--- a/examples/qml/signals/pytoqml2/main.py
+++ /dev/null
@@ -1,55 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-from __future__ import annotations
-
-import os
-from pathlib import Path
-import sys
-from PySide6.QtCore import QObject, QTimer, QUrl, Signal, Slot
-from PySide6.QtGui import QGuiApplication
-from PySide6.QtQuick import QQuickView
-from PySide6.QtQml import QmlElement
-
-
-# To be used on the @QmlElement decorator
-# (QML_IMPORT_MINOR_VERSION is optional)
-QML_IMPORT_NAME = "examples.signals.pytoqml2"
-QML_IMPORT_MAJOR_VERSION = 1
-
-
-@QmlElement
-class RotateValue(QObject):
- valueChanged = Signal(int, arguments=['val'])
-
- def __init__(self):
- super().__init__()
- self.r = 0
-
- @Slot()
- def increment(self):
- self.r = self.r + 10
- self.valueChanged.emit(self.r)
-
-
-if __name__ == '__main__':
- app = QGuiApplication(sys.argv)
- view = QQuickView()
-
- rotatevalue = RotateValue()
- timer = QTimer()
- timer.start(2000)
- view.setInitialProperties({"rotatevalue": rotatevalue})
-
- qml_file = os.fspath(Path(__file__).resolve().parent / 'view.qml')
- view.setSource(QUrl.fromLocalFile(qml_file))
- if view.status() == QQuickView.Status.Error:
- sys.exit(-1)
-
- timer.timeout.connect(rotatevalue.increment)
-
- view.show()
- res = app.exec()
- # Deleting the view before it goes out of scope is required to make
- # sure all child QML instances are destroyed in the correct order.
- del view
- sys.exit(res)
diff --git a/examples/qml/signals/pytoqml2/pytoqml2.pyproject b/examples/qml/signals/pytoqml2/pytoqml2.pyproject
deleted file mode 100644
index e6f087cce..000000000
--- a/examples/qml/signals/pytoqml2/pytoqml2.pyproject
+++ /dev/null
@@ -1,3 +0,0 @@
-{
- "files": ["main.py", "view.qml"]
-}
diff --git a/examples/qml/signals/pytoqml2/view.qml b/examples/qml/signals/pytoqml2/view.qml
deleted file mode 100644
index 2e9128f53..000000000
--- a/examples/qml/signals/pytoqml2/view.qml
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (C) 2021 The Qt Company Ltd.
-// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-
-import QtQuick
-import QtQml
-
-import examples.signals.pytoqml2 1.0
-
-Rectangle {
- id: page
-
- width: 500; height: 200
- color: "lightgray"
- required property RotateValue rotatevalue
-
- Text {
- id: helloText
- text: "Hello world!"
- anchors.horizontalCenter: page.horizontalCenter
- y: 30
- font.pointSize: 24; font.bold: true
- }
-
- Connections {
- target: rotatevalue
- function onValueChanged(val) {
- helloText.rotation = val
- }
- }
-}
diff --git a/examples/qml/signals/qmltopy1/doc/qmltopy1.rst b/examples/qml/signals/qmltopy1/doc/qmltopy1.rst
new file mode 100644
index 000000000..f5d8ece4b
--- /dev/null
+++ b/examples/qml/signals/qmltopy1/doc/qmltopy1.rst
@@ -0,0 +1,13 @@
+Calling Python Methods from QML
+===============================
+
+Introduce how to invoke Python methods (slots) from QML.
+
+**Key Features:**
+
+- **Python Class with Slots:** Defines a Console class in Python with multiple slots using the
+ :deco:`~PySide6.QtCore.Slot` decorator.
+- **Exposing Python Class to QML:** Uses :deco:`~PySide6.QtQml.QmlElement` to make the Console class
+ available in QML.
+- **Calling Slots from QML:** In QML, instantiates Console and calls its methods in response to user
+ interactions.
diff --git a/examples/qml/signals/qmltopy2/doc/qmltopy2.rst b/examples/qml/signals/qmltopy2/doc/qmltopy2.rst
new file mode 100644
index 000000000..3a2518db5
--- /dev/null
+++ b/examples/qml/signals/qmltopy2/doc/qmltopy2.rst
@@ -0,0 +1,12 @@
+Receiving return values from Python in QML
+==========================================
+
+Demonstrate how to call Python methods from QML that return values.
+
+**Key Features:**
+
+- **Python Class with Returning Slot:** Defines a `RotateValue` class with a slot that returns an
+ integer.
+- **Exposing Class to QML:** Uses :deco:`~PySide6.QtQml.QmlElement` to expose RotateValue to QML.
+- **Using Return Values in QML:** Calls the Python method from QML and uses the returned value to
+ update the UI.
diff --git a/examples/qml/signals/qmltopy3/doc/qmltopy3.rst b/examples/qml/signals/qmltopy3/doc/qmltopy3.rst
new file mode 100644
index 000000000..0c94b4b67
--- /dev/null
+++ b/examples/qml/signals/qmltopy3/doc/qmltopy3.rst
@@ -0,0 +1,10 @@
+Handling QML Signals in Python
+==============================
+
+Show how to respond to signals emitted from QML in Python.
+
+**Key Features:**
+
+- **Defining Signals in QML:** Defines custom signals like `buttonClicked` and `textRotationChanged`
+- **Connecting Signals to Python Functions:** In Python, connects these signals to functions.
+- **Handling Signals in Python:** Implements the `sayThis` function to handle the signals.
diff --git a/examples/qml/signals/qmltopy4/doc/qmltopy4.rst b/examples/qml/signals/qmltopy4/doc/qmltopy4.rst
new file mode 100644
index 000000000..70f0082b8
--- /dev/null
+++ b/examples/qml/signals/qmltopy4/doc/qmltopy4.rst
@@ -0,0 +1,11 @@
+Directly Connecting QML Component Signals to Python Functions
+=============================================================
+
+Teach how to connect signals of specific QML components to Python functions using object names.
+
+**Key Features:**
+
+- **Assigning `objectName` in QML:** Sets `objectName` properties to identify QML objects.
+- **Finding QML Objects in Python:** Uses `findChild` to get references to QML objects.
+- **Connecting Component Signals to Python Functions:** Connects signals directly to Python
+ functions.