ContentItem of ListView
-
-
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:-
-
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
-
@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? -
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? -
You can use this library to create the excel file with custom formatting.
-
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) -
@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