[Qt-qml] no basic property define confuse

Eduardo Fleury eduardo.fleury at openbossa.org
Wed Sep 29 20:52:24 CEST 2010


Hi!

In order to an item to be shown on the screen, it needs to belong to the
scene graph, that is, to the three of items that are painted.

When you do this:

Rectangle {
    Text {
        text: "pindamonhangaba"
    }
}

Text is implicitly(*) added as a child of Rectangle, thus it is painted.

However, when you create an item in the context of a property definition,
like in:

Rectangle {
    property Text myProperty: Text {
        text: "foobar"
    }
}

It is not added to the scene graph, thus not painted.


*  *  *

How do I display myText1?


You can either create it in the scene graph directly and fill the property
with its id.

Rectangle {
    property Text myProperty: myText
    Text {
        id: myText
        text: "foobar"
    }
}

or else, use a Loader to show it somewhere else:

Rectangle {
    Loader {
        delegate: myProperty   // assuming this is an initialized property
of type Text
    }
}


(*) See the documentation regarding default properties in Qml for more
detail on why is that.

BR,
Eduardo

-- 
Eduardo M. Fleury
OpenBossa - INdT
http://eduardofleury.com/
http://www.openbossa.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100929/e0dd6d86/attachment.html 


More information about the Qt-qml mailing list