-
-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Efficient loading ListModel data from Python #34
Comments
Yes, we should probably have some kind of list model class that can either store PyObject references or just qvariants. Do you want to modify the list from QML only or from Python or from both? |
I would like to modify the list from Python only. |
import QtQuick 2.0
import io.thp.pyotherside 1.4
Rectangle {
id: root
width: 200
height: 200
Component {
id: fruitDelegate
Row {
anchors.horizontalCenter: parent.horizontalCenter
spacing: 10
Text { text: name } Text { text: '$' + cost }
}
}
ListView {
anchors.fill: parent
id: fruitView
delegate: fruitDelegate
}
Python {
id: py
Component.onCompleted: {
importModule('other_side', function () {
call('other_side.build_model', [], function (result) {
fruitView.model = Qt.createQmlObject(result, root, "dynamicFruitModel")
});
});
}
}
} import pyotherside
def build_model():
return 'import QtQuick 2.0; ListModel { id: fruitModelDynamic; ListElement { name: "Apple"; cost: 2.45 } ListElement { name: "Orange"; cost: 3.25 } ListElement { name: "Banana"; cost: 1.95 }}' Seemingly a working example without JS looping on .append method. However I don't particularity like this "solution". |
I've gone in a different direction and implemented a way to implement a QAbstractItemModel in pure Python. Then a backend can be fully in Python, store the data in Python and access it pythonically, and the QML end just sees a regular model. Details in issue #52. I don't know how this will affect performance though, as it requires every data access from QML to go through Python (though not through a signal). However it may be that with an efficient model implementation, Qt won't keep re-reading the data, or won't retrieve data not in the present views? |
Superseded by #52 |
In this tutorial video, at 39:40, Gabriel de Dietrich emphasized on inefficiency of the following pattern:
In his case, he solved that by sharing the same data from the C++ code.
But C++ is all Greek to me - hence my enthusiasm about pyotherside 😃
In my case, I have a 10k+ list of annotated coordinates (a PCB with a lot of holes). User is supposed to do a lot of hole rearranging and the GUI responsiveness is essential to the workflow.
Presumably without diving in to the C++ code and staying on the py side, how changes to the ListModel can be more efficient?
The text was updated successfully, but these errors were encountered: