[Qt-qml] Recommended way to parametrize QML items?

Pertti Kellomäki pertti.kellomaki at nokia.com
Wed Nov 17 15:40:58 CET 2010


On 11/17/2010 03:59 PM, Junnonen Tomas (Nokia-MS/Helsinki) wrote:
> First try to use a simple direct property binding:
>
> main.qml:
> import Qt 4.7
>
> Rectangle {
>       width: 200; height: 200
>
>       Foo { bar: Text { text: "bar text" } }
>       Foo { bar: Image { source: "bar-image.png" } }
> }
>
> Foo.qml:
> import Qt 4.7
>
> Rectangle {
>       property Item bar
>
>       children: bar
> }
>
> The parametrized bar item doesn't have to be a direct child of Foo
> either. Another way is to use the onBarChanged signal to Do What You
> Want(tm), for example if you need to anchor the item.
>    
Thanks, that clarified things. How do I access bar's anchors within the 
signal handler though? I tried various permutations but did not quite 
figure it out yet.

Could you modify the example so that Foo has a single Text element 
saying "This is bar", positioned just below whatever bar happens to be?

TIA
-- 
Pertti




More information about the Qt-qml mailing list