How to capture an QML child element to an png?
-
You need to wait for Qt 5.3
-
I have an another problem.
With this code:
@
void SessionManager::test(){
QQmlComponent component(pEngine, QUrl::fromLocalFile( "..../Test.qml" ));
QObject *object = component.create();
QQuickItem item = qobject_cast<QQuickItem>(object);
QQuickItem scene = pRootObject->findChild<QQuickItem>("Window1");
item->setParentItem(scene);
QQuickWindow *window = item->window();
QImage image = window->grabWindow();
image.save( "..../test1.jpg" );
}
@-
If I run this function in my main(), before "app.exec()", my view is painted but test1.jpg isn't created.
-
If I launch this function with a mouse control and a signal/slot (I use a notification icon menu to launch my development functions), (so, this function is executed later than the main() initialisation), my view is empty, but I have the jpeg file.
My root object isn't a visible item.
My main.qml looks like this:
@
Item{
Window{
Item{ objectName: "Window1" }
}
Window{
Item{ objectName: "Window2" }
}
Window{
Item{ objectName: "Window3" }
}
}@
So, my "Test.qml" item isn't visible when it is created. But it is showed after the affectation 'setParentItem()'. (except with this problem...)
If I remove the capture, all works fine.
If I move my item to the window2 after the capture, it is visible:@
void SessionManager::test(){
QQmlComponent component(pEngine, QUrl::fromLocalFile( "..../Test.qml" ));
QObject *object = component.create();
QQuickItem item = qobject_cast<QQuickItem>(object);
QQuickItem scene = pRootObject->findChild<QQuickItem>("Window1");
item->setParentItem(scene);
QQuickWindow *window = item->window();
QImage image = window->grabWindow();
image.save( "..../test1.jpg" );
QQuickItem scene2 = pRootObject->findChild<QQuickItem>("Window2");
item->setParentItem(scene2);
}
@
But without that, that doesn't work.It is a bug with QtQuick? Or what?
-
-
Hello,
Have you found the solution for this issue ?
-
Check out "this":http://doc.qt.io/qt-5/qml-qtquick-item.html#grabToImage-method. I think it solves your problem
-
Check out "this":http://doc.qt.io/qt-5/qml-qtquick-item.html#grabToImage-method. I think it solves your problem
-
Yes, The solution has just appeared in Qt 5.4
-
Yes, The solution has just appeared in Qt 5.4
-
[quote author="mehrdad" date="1423500644"]and how?[/quote]Did you read David Stiel's link?
-
[quote author="mehrdad" date="1423500644"]and how?[/quote]Did you read David Stiel's link?