[Qt-qml] Reparent in object initialization

Artem Marchenko artem.marchenko at gmail.com
Wed Jun 22 14:27:37 CEST 2011


Thanks for the advice, Adriano

I didn't check if exposing children works, but probably it does and this makes more sense. Will give it a try in the next project where such variation is needed.

Best regards,
Artem.

On Jun 20, 2011, at 8:03 PM, Adriano Rezende wrote:

> 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/20110622/973f3eac/attachment.html 


More information about the Qt-qml mailing list