diff options
Diffstat (limited to 'examples/quick/models/stringlistmodel')
-rw-r--r-- | examples/quick/models/stringlistmodel/doc/stringlistmodel.png | bin | 0 -> 1978 bytes | |||
-rw-r--r-- | examples/quick/models/stringlistmodel/doc/stringlistmodel.rst | 11 | ||||
-rw-r--r-- | examples/quick/models/stringlistmodel/stringlistmodel.py | 26 | ||||
-rw-r--r-- | examples/quick/models/stringlistmodel/stringlistmodel.pyproject | 3 | ||||
-rw-r--r-- | examples/quick/models/stringlistmodel/view.qml | 17 |
5 files changed, 57 insertions, 0 deletions
diff --git a/examples/quick/models/stringlistmodel/doc/stringlistmodel.png b/examples/quick/models/stringlistmodel/doc/stringlistmodel.png Binary files differnew file mode 100644 index 000000000..eeb9b518a --- /dev/null +++ b/examples/quick/models/stringlistmodel/doc/stringlistmodel.png diff --git a/examples/quick/models/stringlistmodel/doc/stringlistmodel.rst b/examples/quick/models/stringlistmodel/doc/stringlistmodel.rst new file mode 100644 index 000000000..ce11674b4 --- /dev/null +++ b/examples/quick/models/stringlistmodel/doc/stringlistmodel.rst @@ -0,0 +1,11 @@ +String List Model Example +========================= + +.. tags:: Android + +A model may be a simple 'list', +which provides the contents of the list via the modelData role. + +.. image:: stringlistmodel.png + :width: 400 + :alt: String List Model Screenshot diff --git a/examples/quick/models/stringlistmodel/stringlistmodel.py b/examples/quick/models/stringlistmodel/stringlistmodel.py new file mode 100644 index 000000000..3982b1ffc --- /dev/null +++ b/examples/quick/models/stringlistmodel/stringlistmodel.py @@ -0,0 +1,26 @@ +# 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 QUrl +from PySide6.QtGui import QGuiApplication +from PySide6.QtQuick import QQuickView + +# This example illustrates exposing a QStringList as a model in QML + +if __name__ == '__main__': + app = QGuiApplication(sys.argv) + + dataList = ["Item 1", "Item 2", "Item 3", "Item 4"] + + view = QQuickView() + 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/quick/models/stringlistmodel/stringlistmodel.pyproject b/examples/quick/models/stringlistmodel/stringlistmodel.pyproject new file mode 100644 index 000000000..5ec3e85d1 --- /dev/null +++ b/examples/quick/models/stringlistmodel/stringlistmodel.pyproject @@ -0,0 +1,3 @@ +{ + "files": ["stringlistmodel.py", "view.qml"] +} diff --git a/examples/quick/models/stringlistmodel/view.qml b/examples/quick/models/stringlistmodel/view.qml new file mode 100644 index 000000000..5db5576f4 --- /dev/null +++ b/examples/quick/models/stringlistmodel/view.qml @@ -0,0 +1,17 @@ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause + +import QtQuick + +ListView { + width: 100 + height: 100 + required model + + delegate: Rectangle { + required property string modelData + height: 25 + width: 100 + Text { text: parent.modelData } + } +} |