Hi Charley,

On Wed, Nov 24, 2010 at 7:42 PM, Charley Bay <charleyb...@gmail.com> wrote:
> <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)?
>

QML works with properties exposed through the metaobject system
(Q_PROPERTY). So, items have to be extend QObject at some point.
AFAIK, QML supports properties exposed through QObject and user
visible items must be QGraphicsObject or QDeclarativeItem (there are
restrictions like the component's root item must be a QDeclarative
item etc).

> 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?)
>

QDeclarativeView builds on QGraphicsView. So,
QGraphicsItem::boundingRect is still very much used. For a component,
the QGraphicsItem of the component will return the (0, 0, width,
height), so I think your testing above is probably incorrect. I think
opaqueArea is used only for obscurity detection which is not used in
QML and thus left unimplemented.

> What is the intended mechanism by which I interrogate the QGraphicsItem?

As I understand, all QGraphicsItem API should still work as expected
for QML items.

> (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.
>

MouseArea is a QDeclarativeItem. Think of it as a transparent
"overlay" child item that positions itself over the parent. I do not
know why it does not trigger child notifications.

Girish

_______________________________________________
Qt-qml mailing list
Qt-qml@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-qml

Reply via email to