Hi,
I was wondering if someone could tell me if there is a way to instance a QDeclarativeItem (class A, for example) from C++ without using QML and add sub-items to it (like for example MouseArea etc.)
Let me explain a bit more. I know two ways to instance a QDeclarativeItem subclass:
-Either just instance it simply with
A* a = new A();
Like normal variables
-Or, sing a QML file (and in that case I need the view)
QDeclarativeComponent comp (view->engine(),QUrl("file.qml"));
A* a = aobject_cast<A*>(comp.create());
And then the creation uses the default constructor of the class A and loads all the content from the QML file.
The problem of the first solution is that I want my class A to have a MouseArea on it, so, it seems l’ike I need a QML to describe it. But, the problem with the second solution is that I absolutelly need do make a Factory of A’s (a static method in tha class A that takes the view as a parameter). This is quite anoying because in fact the instances of this item are created by another item (in my program) and this item doesn’t know about the view (so I have to change a lot o things in my current code to do that….).
What I was wondering is if there is a n intermediate solution.
Can I instance an A object like this:
A* a = new A();
and somewhere, in the code of the A class put the sub-items I want (such as MouseAreas to make my item clickable?)
May be some thing like this:
A::A(){ //constructor
this->addSubItem(MouseArea m); //but does not exist, I believe...
}
I havent found any method on the documentation to do that, and I believe there is no way to instance a MouseArea…
So, any suggestions, please?
Thank you all!
↧