This will not work, or worse, has undefined behavior. ListView does not instantiate all of its elements - only those that are needed to fill the visible area of the view. If you define the view's height to be the height of its children, but the number of children needed depends upon the height of the view, you're unlikely to get what you want. Why does it seem to work for XmlListModel? Beats me.
I'd suggest doing something like: ListView { height: count * 50 } If you don't want to scroll and you don't need e.g. the currentIndex functionality of the ListView then I'd suggest using a Column with a Repeater. This is more efficient than a ListView and automatically sizes to its content size. Martin. > -----Original Message----- > From: qt-qml-boun...@trolltech.com [mailto:qt-qml-boun...@trolltech.com] On > Behalf Of Pasion Jerome (Nokia-MS-Qt/Oslo) > Sent: Wednesday, 17 November 2010 8:13 AM > To: qt-qml@trolltech.com > Subject: [Qt-qml] ListView's childrenRect > > Hello all, > > Someone sent me his problem with ListView's childrenRect. Essentially, binding > the ListView's height to the childrenRect.height when using a regular > ListModel > (with strings) will only show the first element while using the XmlListModel > will fit all > the model's items. > > Here is his code snippet: > ListView { > id: list > > interactive: false > //height: contentHeight //If bound to contentHeight warning is given > that there > is a binding loop! > height: childrenRect.height //If bound to childrenRect.height then > only one > item is shown (unless you use an XMLListModel!) > //contentHeight: childrenRect.height //Not really necessary > width: parent.width > model: listModel > //model: xmlListModel //If the XMLListModel is used, then the > childrenrect > binding is fine > delegate: listItem > } > } > > What would be the best way of fitting the contents of any/all types of models? > > Cheers, > Jerome P. > > _______________________________________________ > Qt-qml mailing list > Qt-qml@trolltech.com > http://lists.trolltech.com/mailman/listinfo/qt-qml _______________________________________________ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml