In a QtQuick-ListView I want to display different QQuickItems which were instantiated in a C++-Backend. Therefore I created a QObjectList which is used as model:
QObjectList items;
items.append(new MyFirstQuickItem());
items.append(new MySecondQuickItem());
QQmlContext *ctxt = viewer.rootContext();
ctxt->setContextProperty("myModel", QVariant::fromValue(items));
In the ListView, I add the the items as a child of the delegate item:
ListView {
id: view
anchors.fill: parent
model: myModel
delegate: Item {
id: delegateItem
width: 100
height: 50
children: modelData
}
}
With this solution, it is possible to show the items in the list. However, the displayed items have their default size. Is it possible to change the size of the items to the size of the “delegateItem”?
Thanks!
↧