How To Add Dynamic Data To A Qml Table
I'm trying to add rows to a table from Python. I'm using a TableView described with QML. I can't figure out how to add a model to the table, unless the model is also in QML. But I
Solution 1:
Since nobody answered the question yet I will suggest you to use a workaround: Create a javascript function in qml with two arguments and add elements into to table right from QML file.
(Obviously you have to call the function from python first, but thats a piece of cake...)
P.S. If you wanna show example let me know in comment :]
EDIT: code added
import QtQuick 2.3import MyApplication 1.0
QPythonBinding{
id: binding
signal addElement(string param1, string param2)
onAddElement: {
myModel.append({"key1" : param1, "key2" : param2})
}
}
now python code
class QPythonBinding(QQuickItem):
def __init__(self, parent=None):
super(QPythonBinding, self).__init__(parent)
addElement = pyqtSignal(str, str) #you call it like this - addElement.emit("name", "value")
if __name__ == '__main__':
import sys
app = QGuiApplication(sys.argv)
qmlRegisterType(QPythonBinding, "MyApplication", 1, 0, "QPythonBinding")
view = QQuickView()
view.show()
app.exec_()
Post a Comment for "How To Add Dynamic Data To A Qml Table"