[Qt-qml] Parenting with Flickable

michael.brasser at nokia.com michael.brasser at nokia.com
Thu Sep 2 02:26:00 CEST 2010


On 02/09/2010, at 3:44 AM, ext gabriel.dietrich-de at nokia.com wrote:
> I’m currently implementing a position indicator (kind of scrollbar) for the Qt Components project. My first shot, adding it to a ListView as a child worked quite well. Basically, it looks like this:
> 
> ListView {
>    model: ...
>    delegate: ...
> 
>    PositionIndicator { }    <---- Yes, its body is empty
> }
> 
> Inside the PositionIndicator component I’m setting an alias property as the parent of the Item, and using its “visibleArea.*” properties. So far, so good.
> 
> Then I tried with Flickable, like this:
> 
> Flickable {
>    contentWidth: ...
>    contentHeight: ...
> 
>    Rectangle { ... }
> 
>    PositionIndicator { }
> }
> 
> and I get an error about “visibleArea” not being defined. So I decided to set the PositionIndicator as a sibling of the Flickable with a property referencing it:
> 
> Flickable {
>    id: rectFLick
>    contentWidth: ...
>    contentHeight: ...
> 
>    Rectangle { ... }
> }
> 
> PositionIndicator {
>    flickable: rectFLick
> }
> 
> and it works again. Now the questions are,
> 
> 1. What makes the difference between the parenting in ListView and Flickable, and why?

ListView and Flickable have different default properties (which is what the elements get assigned to when no explicit property is specified). In the case of ListView, the element is assigned to data, and becomes a direct child of the list view. In the case of Flickable, the element is assigned to flickableData, and becomes a child of the flickable's contentItem. I've added QTBUG-13346 to better document this difference in behavior.

You should be able to get the ListView behavior with Flickable by directly assigning to the data (or children) property, e.g.

Flickable {
    contentWidth: ...
    contentHeight: ...

    Rectangle { ... }
    
    children: PositionIndicator {}
}

Regards,
Michael





More information about the Qt-qml mailing list