[Qt-qml] no basic property define confuse

Eduardo Fleury eduardo.fleury at openbossa.org
Thu Sep 30 14:03:46 CEST 2010


On Thu, Sep 30, 2010 at 3:47 AM, 罗军 <luoj at neusoft.com> wrote:

>  Can I think Item has two types of element: property and inner item(
> QGraphicsItem)?
>

No, in fact Item have __only__ "properties", of various types. "Inner item"
is just a special situation, but is nothing more than filling a property.

I've added several comments to the code below, and moved the declaration of
inner item to the end so it (hopefully) makes more sense.

Rectangle {
    id: rect

*    // Properties of type "int"*
    width: 200; height: 200

*    // Property of type (Text &)*
*    // These properties are just references to Text objects. Whether these
are being
    // painted or not will depend on them being added to the scene, having
parent, like I said before*
    property Text a;
    property Text b;

*   // A and B are pointers or references to Text objects.
   // Here you initialize "a" by giving the address (id) of an existing Text
object*
    a: foobara  *//   Its relationship is reference object or clone object?
// A: In QML these are always references**

**    // **On the other hand, here you create a new item and save a
reference to in in "b"*
    b: Text {        * **// It's not inner item,  what's it? // A: Don't
think about "inner" item. It's just a new Item whose address you save in "b"
**
*        parent: rect
        y: 20
        text: "foobarb"
    }

  * // Property of type "Gradient"*
    gradient: Grdient {* **// Here, has gradient parent? // A: No sure. But
gradients are not Items, nor they do actual painting. They are just
Rectangle information like "color", "border", etc.*
         GradientStop { position: 0.0; color: "lightsteelblue" }
         GradientStop { position: 1.0; color: "blue" }
    }

*   // Now let's talk about "inner items". Imagine the following, there's a
special property in the outterRect called "data".
   // This property is of type List<QObject *>, in other words, a list of
QML objects.
   // The implementation of Item goes thru every item in this list and
explicitly set a parent-child relationship between the outter item and the
items that are in this list.
   // Now let's fill this property using the syntax below. Here you create
three items and save their references in the list.
*
   data: [
       Text { *// inner item*
            id: foobara
            text: "foobara"
        },
        Image { *// Another "inner item"*
            id: imageA
            source: "photo.jpg"
        },
        Rectangle {* // Another "inner item"*
             id: childRect
             color: "yellow"
        }
    ]

 *   // See, "inner items" are just the items that belong to the property
called "data" of each item. They are handled**
    // in a special way internally and that's just it.
    // The fact you can just create items "floating around" inside an item,
and that this makes them go to the property
    // called "data" is just syntactic sugar. Read about "default
properties" in QML docs and this will be explained.
*
}


-- 
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/20100930/514acf8d/attachment.html 


More information about the Qt-qml mailing list