diff options
Diffstat (limited to 'examples/declarative/objectlistmodel')
-rw-r--r-- | examples/declarative/objectlistmodel/doc/objectlistmodel.png | bin | 1327 -> 0 bytes | |||
-rw-r--r-- | examples/declarative/objectlistmodel/doc/objectlistmodel.rst | 12 | ||||
-rw-r--r-- | examples/declarative/objectlistmodel/objectlistmodel.py | 61 | ||||
-rw-r--r-- | examples/declarative/objectlistmodel/objectlistmodel.pyproject | 3 | ||||
-rw-r--r-- | examples/declarative/objectlistmodel/view.qml | 15 |
5 files changed, 0 insertions, 91 deletions
diff --git a/examples/declarative/objectlistmodel/doc/objectlistmodel.png b/examples/declarative/objectlistmodel/doc/objectlistmodel.png Binary files differdeleted file mode 100644 index 416e08a85..000000000 --- a/examples/declarative/objectlistmodel/doc/objectlistmodel.png +++ /dev/null diff --git a/examples/declarative/objectlistmodel/doc/objectlistmodel.rst b/examples/declarative/objectlistmodel/doc/objectlistmodel.rst deleted file mode 100644 index d71ee61df..000000000 --- a/examples/declarative/objectlistmodel/doc/objectlistmodel.rst +++ /dev/null @@ -1,12 +0,0 @@ -Object List Model Example -========================= - -A list of QObject values can also be used as a model. -A list[QObject,] provides the properties of the objects in the list as roles. - -The following application creates a DataObject class with Property values -that will be accessible as named roles when a list[DataObject,] is exposed to QML: - -.. image:: objectlistmodel.png - :width: 400 - :alt: Object List Model Screenshot diff --git a/examples/declarative/objectlistmodel/objectlistmodel.py b/examples/declarative/objectlistmodel/objectlistmodel.py deleted file mode 100644 index 0843ae480..000000000 --- a/examples/declarative/objectlistmodel/objectlistmodel.py +++ /dev/null @@ -1,61 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -from pathlib import Path -import sys -from PySide6.QtCore import QObject, QUrl, Property, Signal -from PySide6.QtGui import QGuiApplication -from PySide6.QtQuick import QQuickView - -# This example illustrates exposing a list of QObjects as a model in QML - -class DataObject(QObject): - - nameChanged = Signal() - colorChanged = Signal() - - def __init__(self, name, color, parent=None): - super().__init__(parent) - self._name = name - self._color = color - - def name(self): - return self._name - - def setName(self, name): - if name != self._name: - self._name = name - nameChanged.emit() - - def color(self): - return self._color - - def setColor(self, color): - if color != self._color: - self._color = color - colorChanged.emit() - - - name = Property(str, name, setName, notify=nameChanged) - color = Property(str, color, setColor, notify=colorChanged) - - -if __name__ == '__main__': - app = QGuiApplication(sys.argv) - - dataList = [DataObject("Item 1", "red"), - DataObject("Item 2", "green"), - DataObject("Item 3", "blue"), - DataObject("Item 4", "yellow")] - - view = QQuickView() - view.setResizeMode(QQuickView.SizeRootObjectToView) - view.setInitialProperties({"model": dataList}) - - qml_file = Path(__file__).parent / "view.qml" - view.setSource(QUrl.fromLocalFile(qml_file)) - view.show() - - r = app.exec() - del view - sys.exit(r) diff --git a/examples/declarative/objectlistmodel/objectlistmodel.pyproject b/examples/declarative/objectlistmodel/objectlistmodel.pyproject deleted file mode 100644 index 556e399f4..000000000 --- a/examples/declarative/objectlistmodel/objectlistmodel.pyproject +++ /dev/null @@ -1,3 +0,0 @@ -{ - "files": ["objectlistmodel.py", "view.qml"] -} diff --git a/examples/declarative/objectlistmodel/view.qml b/examples/declarative/objectlistmodel/view.qml deleted file mode 100644 index b7cf68a9b..000000000 --- a/examples/declarative/objectlistmodel/view.qml +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import QtQuick - -ListView { - width: 100; height: 100 - - delegate: Rectangle { - color: model.modelData.color - height: 25 - width: 100 - Text { text: model.modelData.name } - } -} |