Establecer elementos en QML ListModel dinámicamente con PyQt
Tengo un QML que representa la programación, que obtiene valores de la base de datos, por lo que necesito insertar valores paraListModel
de mi código de python. QML se ve así:
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
}
}
}
Y yo una función, que debería insertar valores a 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")
No tengo ideas de cómo hacer eso. ¿Usted me podría ayudar por favor? Estoy usando Python2.7, PyQt5.9, QtQuick2.5