Scrolling Example

A Python application that demonstrates how to use a qml view and make it scrollable.

Scrolling Screenshot
import os
from pathlib import Path
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)

    qml_file = os.fspath(Path(__file__).resolve().parents[1] / 'usingmodel' / 'view.qml')
    if view.status() == QQuickView.Error:

    # 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