Guest User

main.py

a guest
Nov 12th, 2021
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.19 KB | None | 0 0
  1. import sys
  2.  
  3. from PySide6.QtGui import QGuiApplication
  4. from PySide6.QtQml import QQmlApplicationEngine
  5. from PySide6.QtCore import (
  6.     QTimer,
  7.     Qt,
  8.     QUrl,
  9.     QAbstractListModel,
  10. )
  11.  
  12. class Model(QAbstractListModel):
  13.  
  14.     def __init__(self, parent=None):
  15.         QAbstractListModel.__init__(self, parent)
  16.         self.row_count = 200
  17.  
  18.     def update_model(self, rows):
  19.         self.beginResetModel()
  20.         self.row_count = rows
  21.         self.endResetModel()
  22.  
  23.     def rowCount(self, parent):
  24.         return self.row_count
  25.  
  26.     def data(self, index, role=Qt.DisplayRole):
  27.         ix = index.row()
  28.         if ix < self.row_count:
  29.             return "Row {:d}".format(ix)
  30.  
  31. timer = None
  32. model = Model()
  33.  
  34. def on_timer_expire():
  35.     model.update_model(0)
  36.     timer.stop()
  37.  
  38. if __name__ == "__main__":
  39.     app = QGuiApplication(sys.argv)
  40.     engine = QQmlApplicationEngine()
  41.  
  42.     engine.rootContext().setContextProperty("pythonModel", model)
  43.     engine.load(QUrl("qtbug1.qml"))
  44.  
  45.     timer = QTimer()
  46.     timer.timeout.connect(on_timer_expire)
  47.     timer.start(3000)  # 3 seconds
  48.  
  49.     if engine.rootObjects():
  50.         sys.exit(app.exec())
  51.     else:
  52.         sys.exit(1)
  53.  
Advertisement
Add Comment
Please, Sign In to add comment