scrolling.py

import os
import sys
from PySide6.QtCore import QUrl
from PySide6.QtGui import QGuiApplication
from PySide6.QtQuick import QQuickView

# This example uses a QML file to show a scrolling list containing
# all the items listed in dataList.

if __name__ == '__main__':
    dataList = ["Item 1", "Item 2", "Item 3", "Item 4"]

    app = QGuiApplication(sys.argv)
    view = QQuickView()

    ctxt = view.rootContext()
    ctxt.setContextProperty("myModel", dataList)

    qmlFile = os.path.join(os.path.dirname(__file__), 'view.qml')
    view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile)))
    if view.status() == QQuickView.Error:
        sys.exit(-1)
    view.show()

    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