0
我有一個QML表示從數據庫獲取值的計劃,因此我需要從我的Python代碼中插入值到ListModel
。 QML看起來像這樣:使用PyQt將項目設置爲QML ListModel動態模式
我一個功能,應該插入值QML的ListModel:
class ScheduleView(QObject):
def __init__(self, parent=None):
QObject.__init__(self, parent=parent)
self._presenter = SchedulePresenter(self)
self._widget = QQuickWidget(parent)
self._widget.rootContext().setContextProperty('scheduleView', self)
self._widget.rootContext().setContextProperty('groupsModel', self)
self._widget.setSource(QUrl('modules/schedule/Form.qml'))
def reprSchedules(self):
values = [{"lesson": "1", "subject": "PE", "day": "Monday"},
{"lesson": "2", "subject": "PE", "day": "Monday"},
{"lesson": "3", "subject": "PE", "day": "Monday"}]
#model = self._widget.rootObject().findChild(QObject, "scheduleModel")
我沒有任何想法如何做到這一點。請問你能幫幫我嗎?我使用的是Python2.7,PyQt5.9,QtQuick2.5