Unsolved ContentItem of ListView
-
try:
console.log(listView.model.count) for(var i=0; i< listView.model.count; i++) { console.log(listView.model.get(i).text) }
-
Thank you but my problem is different, because I have some logic in the delegate.
See this exampleText {
id: itexItem
font.pixelSize: 40
text: model.text === "10"? "Test" : model.text
}So I can't use model, but I should ListView the text of delegate
-
Hi @alemio , your code is working fine for me
ListView{ id:listView width: 100 height: 100 model: listModel delegate: Rectangle { id: delegateItem width: parent.width; height: 100 Text { id: itexItem font.pixelSize: 40 text: model.text === "10"? "Test" : model.text } } }
Sample Output:-
-
@alemio said in ContentItem of ListView:
because I have some logic in the delegate.
The delegate is just for painting it should not contain data logic. You should move that logic in a proxy model
-
This post is deleted! -
Thank you, but so the answer is that I can't use the contentItem to see all items in the ListView, right?
are all items added/deleteded dinamically to the contentItem?
-
@alemio said in ContentItem of ListView:
are all items added/deleteded dinamically to the contentItem?
Yes. ListView destroys items out of viewport.
-
Ok, I'll explain my problem better, maybe it will be easier.
I would like to export a ListView to Excel. In my real project I have a a model and a proxymodel but it has more fields than the ListView and the order is different. If the way is use proxymodel, how can I do that? -
@alemio said in ContentItem of ListView:
In my real project I have a a model and a proxymodel
@alemio said in ContentItem of ListView:
how can I do that?
As mentioned, you should move the logic you currently have in the delegate to the proxy model and use that to save.
Is your model a QML model or a C++(QAbstractItemModel
) one? -
The model is a c++ model QAbstractItemModel. I have a unique model for each table in the database (autogenerated from orm). I have also a proxymodel for these c++ model
-
My proxy model is derived from SortFilterProxyModel
@VRonin Tell me please if I have a colored row or different font, how can I export that in excel?
-
You can use this library to create the excel file with custom formatting.
-
@VRonin I've already taken this library.
I just need to understand how put some logic in proxy model as you told me.
I saw DelegateModel component, but I don't find example how can I extract data in c++ (I think at the end it is the same problem like listview delegate) -
@alemio said in ContentItem of ListView:
I just need to understand how put some logic in proxy model
It's not really clear what exactly you are doing but I suspect you'd want to override the
data()
method of the proxy to convert some value in the base model to a different value in the proxybut I don't find example how can I extract data in c++
Check out
JsonModelSerialiserPrivate::toJsonObject
of this file for an example. this extracts the data and saves it in a JSON object, you basically have to do the same but save it in an excel file