I am writing a QML extension plugin and I am looking for a way to access the size of an element that has just been implemented.
Now a new element (named CustomElement ) can be created with any size that the user wants by defining the values โโof width and height , so on a QML file that the user can make:
CustomElement { id: my_elem width: 800 height: 600 }
But I would like to get size information when the user adjusts the size using anchor , for example:
Rectangle { width: 800 height: 600 CustomElement { id: my_elem anchors.fill: parent } }
I do not know how to access anchors information.
The plugin class is defined as:
class CustomElement: public QDeclarativeItem { Q_OBJECT
In the plugin constructor, I set QGraphicsItem::ItemHasNoContents to false:
CustomElement::CustomElement(QDeclarativeItem* parent) : QDeclarativeItem(parent) { qDebug() << "CustomElement::CustomElement parent is:" << parent; setFlag(QGraphicsItem::ItemHasNoContents, false); }
After adding debugging, I noticed that parent is 0 , which explains why I cannot get useful information using the boundingRect() and others methods. Apparently the problem is that my plugin does not have a parent. How to solve this problem?
karlphillip
source share