Extract QImage from QQuickItem
Hi,
I would like to process an image loaded into a Flickable QML element in C++ land but I am failing to obtain the original image. So far I'm only seem able to obtain an image of the QQuickWindow
and would liek to know if there is a way to obtain the whole loaded image.
I am calling a Q_INVOKABLE method of a C++ object as follows:
Code:
Flickable {
id: content
clip: false
anchors.fill: parent
boundsBehavior: Flickable.StopAtBounds
Loader {
id: contentLoader
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
onClicked: {
console.log("[veo] onClicked - capture triggered")
cplusplusobject.process(contentLoader.item) <----------------- call to C++
}
}
In C++ I have:
Code:
void
Cplusplusobject
::process(const QVariant &v
){
qDebug() << "[veo]" << __FUNCTION__;
QQuickItem *item = qobject_cast<QQuickItem *>( v.value<QObject*>() );
qDebug() << "Item dimensions:" << item->width() << item->height();
item->dumpObjectInfo();
QQuickWindow *window = item->window();
QImage image
= window
->grabWindow
();
...
The printed item dimensions do correspond to the original image but I fail to see how to turn the QQuickItem into a QImage.
Any suggestions please?
Re: Extract QImage from QQuickItem
Up
I'm also interested by an answer.
I would like to store an child QML item to an image.
Currently, I use the grabWindow() method. It works, but this isn't what I want. This stores the whole window.
I saw this method, which looks right:
http://stackoverflow.com/questions/1...ving-qml-image
But QtDeclarativeItem is obsolete, and QQuickItem hasn't got a Paint() method.
I tried to use the QQuickPaintedItem class, which has got a paint() method, but it is virtual. I don't know how to use it in my case (I'm a newbie).
Re: Extract QImage from QQuickItem
I am also interested in that. Does anyone get it?
Re: Extract QImage from QQuickItem
In Qt Quick items are OpenGL primitives. If you want to get them as images, you have to force the item to be rendered on a texture, e.g. using ShaderEffectSource and then use QQuickItem API to identify the texture so that you can download it from the atlas. That is not something straightforward though.
Re: Extract QImage from QQuickItem
If the item is fully visible, you could grab a screenshot of the window (QWindow::grabWindow()) and the copy the area of the item into the target image.
Cheers,
_