[Qt-qml] no basic property define confuse
罗军
luoj at neusoft.com
Fri Oct 8 02:48:56 CEST 2010
Thank your reply.
From: Eduardo Fleury
Sent: Thursday, September 30, 2010 8:03 PM
To: 罗军
Cc: qt-qml at trolltech.com
Subject: Re: [Qt-qml] no basic property define confuse
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/
---------------------------------------------------------------------------------------------------
Confidentiality Notice: The information contained in this e-mail and any accompanying attachment(s)
is intended only for the use of the intended recipient and may be confidential and/or privileged of
Neusoft Corporation, its subsidiaries and/or its affiliates. If any reader of this communication is
not the intended recipient, unauthorized use, forwarding, printing, storing, disclosure or copying
is strictly prohibited, and may be unlawful.If you have received this communication in error,please
immediately notify the sender by return e-mail, and delete the original message and all copies from
your system. Thank you.
---------------------------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20101008/a5f6d34b/attachment.html
More information about the Qt-qml
mailing list