[Qt-qml] Reparent in object initialization
Adriano Rezende
adriano.rezende at openbossa.org
Mon Jun 20 19:03:20 CEST 2011
On Tue, Jun 14, 2011 at 4:07 PM, Artem Marchenko
<artem.marchenko at gmail.com>wrote:
> Hi
>
> I didn't try this code, but in general it should work.
>
Yes, it works. But I want a guarantee that it won't change in the future due
to an internal change in the QML code.
What I did try is to defined some parts of a scene in the descendant object
> (like you would do in a Strategy pattern for coding) and reparenting works
> very well there, even anchors are accounted correctly. For example, in my
> cross-platform app I need to draw status line on Symbian only:
>
> BaseUi.qml
> Rectangle {
>
> // to be filled for platforms that need it
> property alias statusLine: mainPane.statusLine
>
> // needs to be exposed so that I could parent to it
> property alias mainPane: mainPane
>
> Rectangle {
> id: mainPane
> property variant statusLine: null
> }
> }
>
> SymbianUi.qml
>
> BaseUi {
> statusLine: Rectangle {
> parent: mainPane
> anchors.left: parent.left // yep, this also works
> }
> }
>
>
In your case I think it's better to use children property, so you don't need
to expose the parent. It could be like below:
BaseUi.qml
===
Rectangle {
property alias statusLine: mainPane.children
Rectangle {
id: mainPane
anchors.fill: parent
anchors.margins: 10
}
}
SymbianUi.qml
===
BaseUi {
statusLine: Rectangle {
anchors.fill: parent
}
}
Br,
Adriano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20110620/fb9359e6/attachment.html
More information about the Qt-qml
mailing list