[Interest] QML: How to create reusable containers?

Sivan Greenberg sivan at omniqueue.com
Wed May 16 16:28:53 CEST 2012


Hello Aekold,

On Wed, May 16, 2012 at 5:15 PM, Aekold Helbrass <helbrass at gmail.com> wrote:
> Lame question which I cannot figure out myself: how to create reusable
> container components in QML?
> Here is what I have in mind:
>
>    Rectangle {
>        Header {
>        }
>
>        <body goes here>
>
>        Row {
>            anchors.bottom: parent.bottom
>            anchors.right: parent.right
>            Button { text: "OK" }
>            Button { text: "Cancel" }
>        }
>    }
>

If I understand your question correctly, you want to have one
'template' qml to use and everytime put a different body depending on
the current interaction.

You could actually create[0] a component that would have the 'header'
and 'footer' as you just noted, and have a Loader[1] in its body and
introduce a property from the top level 'container' that would allow
you to set the Loader's source file. You could then, depending on the
current state change the source property and have a different 'body'
in your one template.

HTH,

-Sivan

[0]: http://doc.qt.nokia.com/4.7-snapshot/qml-component.html
[1]: http://doc.qt.nokia.com/4.7-snapshot/qml-loader.html#details



More information about the Interest mailing list