I have a QML that represent schedule, that get values from database, so I need insert values to ListModel
from my python code. QML looks like that:
function append(newElement) {
scheduleList.model.append(newElement)
}
ListView {
id: scheduleList
model: scheduleModel
delegate: scheduleItem
section.property: "day"
section.delegate: sectionDelegate
}
Component {
id: scheduleItem
Rectangle {
Row {
spacing: 15
Text {
text: lesson
}
Text {
text: subject
}
}
}
}
Component {
id: sectionDelegate
Rectangle {
id: root
Text {
id: label
text: section
}
}
}
And I a function, that should insert values to 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")
I have no ideas how to do that. Could you help me, please? I'm using Python2.7, PyQt5.9, QtQuick2.5