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
© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.