Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
New Contributor
Gundersen
Posts: 5
Registered: ‎12-26-2012
My Device: blackberry 10 alpha device
Accepted Solution

[QML] reset properties when ListItemComponent is reused

When ListItemComponents are reused in ListViews, the properties of Controls are not reset. So if you for example scale or rotate a Control, then many other items in the list will also be scaled or rotated. Is there a signal I can listen to which will tell me when the contents of the ListItemComponent has been altered (which would be when it is reused) so I can reset the properties?
Please use plain text.
Developer
Hithredin
Posts: 404
Registered: ‎06-03-2010
My Device: Z10 Red

Re: [QML] reset properties when ListItemComponent is reused

I spent some time to get a 'recycled' signal by digging in cascades listview system. But without success. The only way I found is to bind every value that can change to a default value inserted with the item to the datamodel.
Please use plain text.
New Contributor
Gundersen
Posts: 5
Registered: ‎12-26-2012
My Device: blackberry 10 alpha device

Re: [QML] reset properties when ListItemComponent is reused

So the solution is to listen to a change event on one of the controllers in the listItemComponent. So for example, if you have an image where you set the imageSource with data from the DataModel, then listen to onImageChange to reset the properties.

 

ListView {
    dataModel: _seenit.model
    
    listItemComponents: ListItemComponent {
        ImageView {
            id: img
            image: ListItemData.image
            onImageChanged: {
                img.scaleX = 1;
                img.scaleY = 1;
                img.translationX = 0;
                img.translationY = 0;
            }
        }
    }
}

Please use plain text.
Developer
Hithredin
Posts: 404
Registered: ‎06-03-2010
My Device: Z10 Red

Re: [QML] reset properties when ListItemComponent is reused

Does it work even if two items have the same image?

Please use plain text.