[Qt-qml] Adjusting Flickable contentHeight to variable children ListViews

1,173 views
Skip to first unread message

Matti Mäki

unread,
Oct 11, 2011, 4:22:39 AM10/11/11
to qt-...@qt.nokia.com
Hi,

Flickable {

contentHeight: //..?

ListView {
visible: // always
contentHeight: // fixed
}
ListView {
visible: // always
contentHeight: // fixed
}
ListView {
visible: // sometimes
contentHeight: // variable
}
}

How should I define the Flickable contentHeight so it will adjust
correctly to the changing children? Binding to childrenRect.height does
not seem to do the job. The two upper ListView's are always visible and
have fixed heights but the third is shown only when user expands it, and
it might have any number of elements from 1 to 20 or something.

/matti
_______________________________________________
Qt-qml mailing list
Qt-...@qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-qml

jens.ba...@nokia.com

unread,
Oct 11, 2011, 5:05:47 AM10/11/11
to matti...@iki.fi, qt-...@qt.nokia.com
Unless you put those ListViews in a Column (or anchor them) and explicitly set their height (bind each view's height to its own contentHeight), the childrenRect will not make sense. They are all stacked on top of each other right now. Also, I suspect you should set the interactive flag to false on the ListViews so they don't interfere with top-level Flickable. For the fixed height views, you could alternatively have used repeaters instead of ListViews.

Regards,

Jens

Matti Mäki

unread,
Oct 11, 2011, 9:17:10 AM10/11/11
to qt-...@qt.nokia.com
Sorry, I omitted too much code. The ListView's actually are anchored to
each others.

Explicit height is not viable for the third ListView because item count
will vary. There would be excess space below items which is not nice.
Maybe I can hack out a function that will calculate the new height
whenever the item count changes. "item_count * delegate_height" or
something.

And thanks for the tip, I changed first and second ListViews to
Columns+Repeaters. Although they already had interactive set false.

/matti

jens.ba...@nokia.com

unread,
Oct 11, 2011, 9:45:26 AM10/11/11
to matti...@iki.fi, qt-...@qt.nokia.com
> Explicit height is not viable for the third ListView because item count
> will vary. There would be excess space below items which is not nice.
> Maybe I can hack out a function that will calculate the new height
> whenever the item count changes. "item_count * delegate_height" or
> something.

You should not have to. Did you try to just explicitly set the height of the last ListView to it's own contentHeight?
The ChildrenRect of your Flickable should then automatically stay in sync.

Jens

Reply all
Reply to author
Forward
0 new messages