[Qt-qml] C++ MyClass to detect child added/removed from QML

Charley Bay charleyb123 at gmail.com
Wed Nov 24 15:12:28 CET 2010


<snip, detect parent/child changes from QML in C++>

Martin spaketh:

>  QGraphicsItem::itemChange() may do what you want:
>
>
>
> http://doc.qt.nokia.com/4.7-snapshot/qgraphicsitem.html#itemChange
>

Works great!  Thanks!

Related question:  Now that I'm in the QGraphicsItem world, which is *not* a
QObject with properties, how does QML expose attributes (since those are
*all* properties based)?

For example, the QGraphicsItem::boundingRect() is always (0,0,-1,-1), even
though the referenced QML component *has* width and height.  Similarly, the
QGraphicsItem::opaqueArea()::boundingRect() is always (0,0,0,0).  Does the
QGraphicsItem have *any* opinion about or state from attributes in the QML
element?  (e.g., what attributes can I trust in the QGraphicsItem as being
those used by the QML element?)

What is the intended mechanism by which I interrogate the QGraphicsItem?
(Is the expectation that the user will merely attempt to downcast to
QGraphicsObject or QDeclarativeItem, handling the scenarios where it is not
that type?)  For examle, I *assume* that the MouseArea will trigger child
notification, but it is not a QDeclarativeItem.  In contrast, a Rectangle{}
or Text{} trigger child notification, and "happen to be" QDeclarativeItem
instances.

Thanks!

--charley
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20101124/e8f1d751/attachment.html 


More information about the Qt-qml mailing list