I have a ListView with a simple model which in turn also has a model which is actually displayed:
ListView {
Component.onCompleted: console.log("ListView height: " + height)
model: ["1"]
delegate: Column {
Component.onCompleted: console.log("Inner delegate height: " + height)
Repeater {
model: ["A", "B"]
delegate: Text {
Component.onCompleted: console.log("Text height: " + height)
text: modelData
}
}
}
}
I can get the Text and the Column height. Even though ListModel knows the Column height, it still has zero height.
My question is: how to properly assign ListView the given size?
The program outputs:
qml: Text height: 14 qml: Text height: 14 qml: Inner delegate height: 28 qml: ListView height: 0
ListViewadjusts its height to fit content. SinceListViewderived fromFlickableit have to becontentHeight, notheight. So you have to set size ofListViewmanually, with anchors or layoutsListViewhere? Just put theColumnin aFlickable. Shorter, simpler code with the same visual outcome.ListViewwill be easier. The example in the question was a bit unfortunate to show only one item,1, in the outer model.