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
ListView
adjusts its height to fit content. SinceListView
derived fromFlickable
it have to becontentHeight
, notheight
. So you have to set size ofListView
manually, with anchors or layouts – folibisListView
here? Just put theColumn
in aFlickable
. Shorter, simpler code with the same visual outcome. – BaCaRoZzoListView
will be easier. The example in the question was a bit unfortunate to show only one item,1
, in the outer model. – szotsaki