Subclassing QML Image item
Hello,
I’m trying to create a QML Image item from a C++ class, for dynamically adding image into a QDeclarativeView.
I found that I need to herit from QDeclarativeItem and to implement paint(…).
Isn’t it possible to directly use/herit the QML item Image [doc-snapshot.qt-project.org]” instead? Like this, I would only need to set the property “source” by my self, and the painting, the scaling, the fitting, … will be managed automatically like Image [doc-snapshot.qt-project.org]” item from QML component did?
2 replies
Hi,
It isn’t possible to use or inherit QDeclarativeImage directly from C++ (it is a private class). One option for creating and manipulating Image elements from C++ is the following:
- QQmlEngine engine;
- QQmlComponent component(&engine);
You could then set the source either via QObject::setProperty(), or by manipulating the string passed to setData().
Regards,
Michael
Thanks for the reply,
it was already what I did (I suppose you mean QDeclarativeComponent in Qt 4.8.1), except that I was loading a nearly empty QML file :
But it’s still not allowing me to get a C++ class like MyImage which would also be a QDeclarativeImage.
I was needing a direct inherit from my C++ class to the declarative class for easily founding my C++ class from the parent item of an other QML item using findChild.
You must log in to post a reply. Not a member yet? Register here!



