Center list view vertically
-
Hey,
I have a rectangle with a specific height (which doesn't change) and a ListView inside this rectangle. Normally I use anchors.fill: parent on the listview, but now I get this problem: When the listview contains only 2-3 elements, it is smaller than the rectangle so there is space over below the last item.
What can I do if I want to center the items like in the picture below:
!http://i.imgur.com/J9u6e.png(QML ListView: Layout centered)!I tried to use something like this:
@ ListView {
anchors.fill: parent // When not having this line, the list has height 0
anchors.verticalCenter: parent.verticalCentermodel: testmodel delegate: Text { text: name + ": " + number } }@
It didn't work.
Does anyone know how to achieve something like that?
Thanks in advance!
D. -
You may put your ListView in another container such as Item, which will be vertically centered in main Container from picture. And don't forget to set inner Item height to -listView.height- and width to parent.width.
UPD use listView.contentHeight instead of listView.height. Of maybe you will need their combination.
I can't test it now, but it should works.