Using TableView as ListView-delegate
-
I have a
model
that contains severalQStandardItemModels
. Now I want to create a view that displays aTableView
for each of theseQStandardItemModels
.
I had the idea to have aListView
that has aTableView
as delegate, something like this:ListView { id: myListView anchors { fill: parent margins: 5 } model: testModel delegate: CompareDelegate { } }
And in
CompareDelegate.qml
:Item { id: base width: 500 height: 300 TableView { anchors.fill: parent } }
How do I get the
TableView
inside the delegate to use the appropriateQStandardItemModel
within the model of theListView
?
I hope the question is somewhat clear.Thanks in advance.
-
@qwasder85 A simple way would be to keep a
Q_INVOKABLE
function or a public slot in your model which will return these individualQStandardItemModels
based on some property. Now since theTableView
is inside the delegate assigned toListView
you can make use ofindex
property and pass it to the function which will return the model. Something likeItem { id: base ... TableView { anchors.fill: parent model: myListView.model.getModel(index) //or testModel.getModel(index) } }