Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from PySide6.QtGui import QGuiApplication
- from PySide6.QtQml import QQmlApplicationEngine
- from PySide6.QtCore import (
- QTimer,
- Qt,
- QUrl,
- QAbstractListModel,
- )
- class Model(QAbstractListModel):
- def __init__(self, parent=None):
- QAbstractListModel.__init__(self, parent)
- self.row_count = 200
- def update_model(self, rows):
- self.beginResetModel()
- self.row_count = rows
- self.endResetModel()
- def rowCount(self, parent):
- return self.row_count
- def data(self, index, role=Qt.DisplayRole):
- ix = index.row()
- if ix < self.row_count:
- return "Row {:d}".format(ix)
- timer = None
- model = Model()
- def on_timer_expire():
- model.update_model(0)
- timer.stop()
- if __name__ == "__main__":
- app = QGuiApplication(sys.argv)
- engine = QQmlApplicationEngine()
- engine.rootContext().setContextProperty("pythonModel", model)
- engine.load(QUrl("qtbug1.qml"))
- timer = QTimer()
- timer.timeout.connect(on_timer_expire)
- timer.start(3000) # 3 seconds
- if engine.rootObjects():
- sys.exit(app.exec())
- else:
- sys.exit(1)
Advertisement
Add Comment
Please, Sign In to add comment