[Qt-qml] ListView and visible items

jaakko.korpela at nokia.com jaakko.korpela at nokia.com
Sun Feb 6 18:15:48 CET 2011


>>Note that you can't match list item's y property against 
>>ListView's contentY, as both are in their local coordinates.
>
>I believe you can...

Yes... of course you can. Initially I had some weird issues and every list delegete seemed to have its y pos at zero, which makes no sense since item's position is relative to its parent.

>Keep in mind that the javascript monster (sorry :D) will get evaluated on every frame of the scrolling animation as many times as there are
>instantiated delegates (having cacheBuffer naturally makes things worse). I don't know what platform you're targeting, but at least on Symbian you
>have to be careful in order to get good performance. I think it might be feasible to do these types of things also in c++ side. All the properties you
>can use in javascript are also available in the c++ side by using the metaobject system and pointers of qml elements can be passed as parameters to
>c++ methods. I guess the delegates should get an insideListViewBounds attached property or something (don't know though what the overhead is for cases
>where it's not needed).

>If you take into consideration what Adriano said about the coordinates you should be able to simplify the logic a bit. Also wouldn't it be simpler to
>organize the logic so that you're checking for non-visibility rather than visibility? I mean check that the delegate y + height is less than
>contentYor delegate y is more than the content bottom and then do a ! in the onChanged handler.

>Juha

You are right. The logic is much less monstrous if you check for non-visibility (as Adriano illustrated):

property bool outOfBounds: y > ListView.view.contentBottom || y + height < ListView.view.contentY
onOutOfBoundsChanged: if (!outOfBounds && ListView.view.moving) triggerSomeAction()

With ListView, the default cacheBuffer is zero, so in order to make with this solution work, that has to be increased so that items are not deleted the moment they disapppear from view. And thank you for raising the issue of performance. It certainly is something that needs to be carefully contemplated.

/Jaakko


More information about the Qt-qml mailing list