On 11/17/2010 02:20 PM, Kellomaki Pertti (Nokia-MS/Tampere) wrote: > What is the recommended way to parametrize QML items? What I would like > to achieve is something the following. The intent is to create a Foo > where one part of the visual appearance is given by the bar property. > > Foo { bar: Text { text: "bar text" } } > Foo { bar: Image { source: "bar-image.png" } } > > Looking at SpinBox.qml in the custom branch of qt-components [1], I see > that one way to do this is to use a Loader element as a place holder > inside the definition of Foo, and set it up in the onLoaded handler. > This is clear enough, though it does look like a bit roundabout way of > doing things.
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. Regards, Tomas _______________________________________________ Qt-qml mailing list Qt-qml@trolltech.com http://lists.trolltech.com/mailman/listinfo/qt-qml