QML ListView with variable Item heights
-
wrote on 14 Jan 2016, 13:23 last edited by Dev1337
Hi there,
so i am trying to build a ListView like the Facebook timeline.
The Items in the ListView should have a variable Item height.Is there a way to do this?
Right now i am using a Column with an Repeater inside but this got a huge performace problem to show more than 50 Objects. ( it gets choppy/slow @ scrolling) -
wrote on 14 Jan 2016, 13:59 last edited by A Former User
Hi! You need to define your own delegate. See http://doc.qt.io/qt-5/qml-qtquick-listview.html#delegate-prop
-
wrote on 14 Jan 2016, 23:47 last edited by
My delegate looks like this :
Item {
height: text.height + 40px
Width: 400pxText {
id: text
Width: parent.Width
anchors.verticalCenter:parent.verticalCenter
text: "some random text, but the text can have up to 10 rows so the height is not fix"
}
}So the ListView can handle Items with a variable height? I thought the ListView needs items with fixed Heights? Or am I wrong?
-
wrote on 15 Jan 2016, 00:06 last edited by
@Dev1337 said:
So the ListView can handle Items with a variable height?
Yes, no problem. Take a look at this image: https://drive.google.com/file/d/0B2D1UtsPfTx-aGR4TmxVLWNUX3M/view?usp=sharing. On the left side is a ListView. It has items with a small hight (the ones with black background) and items with variable hight depending on the amount of text they contain. (In this image these text items all have the same hight only because they all contain the same dummy text.)
1/4