Element and Event inspection in QML (QT Declarative)
I am doing some tests in Qt Quick (Qt Declarative and QML), and i would like to inspect the elements composing the declarative interface.
For example, if i have a declarative GU开发者_如何转开发I composed of a rectangle and two images, i would like to have a list with three (or more) elements with these widgets (or items in Qt Declarative).
In Qt4 it is as easy as call the QApplication::allWidgets() method, bout i don't know how to do it in QML.
The same happens with event filters, so i can not get the events sent to these items.
Cheers!!!
You can get the root object this way:
QGraphicsObject * QDeclarativeView::rootObject () const
which gives you a QGraphicsObject, and then you can use:
QList<QGraphicsItem *> QGraphicsObject::childItems () const
childItems() is actually defined in QGraphicsItem, QGraphicsObject is child class of QGraphicsItem
精彩评论