[Qt-qml] ListView and visible items

Adriano Rezende adriano.rezende at openbossa.org
Thu Feb 3 21:16:45 CET 2011


On Thu, Feb 3, 2011 at 12:39 PM,  <jaakko.korpela at nokia.com> wrote:
>    Component {
>        id: listDelegate
>
>        Item {
>            ...
>            property bool isVisible : (((index * height) >= ListView.view.contentY &&
>                                        (index * height) <= ListView.view.contentBottom) ||
>                                       ((index * height) + height >= ListView.view.contentY &&
>                                        (index * height) + height <= ListView.view.contentBottom))
>
>            onIsVisibleChanged: { if (isVisible && ListView.view.moving) triggerSomeAction(); }
>        }
>    }
>
> 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. The ListView items are in local coordinates but
they are children of ListView.contentItem and ListView.contentY is
equal to -ListView.contentItem.y. So, for example, if contentItem.y
goes up 30 pixels, contentY increases 30 pixels while all items stays
at the same absolute position. If an item y position is equal to 30 px
(which is relative to contentItem), it will be at the top of the
visible bounding rect when contentY == item.y == 30 (I'm assuming you
will not touch in contentItem matrix transformation).

Is there a use case where it fails?

Br,
Adriano


More information about the Qt-qml mailing list