Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Stronger way to render a QQuickItem (WebView) into an Image
Using the WebKit version of the Qt 5.4.0, I need to be able to print the content of a WebView :
Because I can't see any answer from the QML part, I have tried with the C++ part:
QmlItemPrinter::print(const QVariant &qmlItem)
QQuickItem *item = qobject_cast<QQuickItem >( qmlItem.value<QObject>() );
By googling, I have already tried different solution:
The GrabWindow: -> Only works for the visible part of the WebView. But My webView have a contentHeigh of 23000.
The grabToImage + ShaderEffectSource -> Image have the good size, but its contents is like the content of the resized grabWindow:
The QQuickPaintedImage: Yes but how can I implement its paint method ?
The QSGTextureProvider seems to not work with big WebView content:
QSGTextureProvider *textureProvider = item->textureProvider();
QSGTexture *texture = textureProvider->texture();
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_COMPONENTS, &internalFormat); // get internal format type of GL texture
QImage image(texture->textureSize(), QImage::Format_RGBX8888);
glGetTexImage(GL_TEXTURE_2D, 0, internalFormat, GL_UNSIGNED_BYTE, image.bits());
The QGraphicsObject: It seems that the WebView cannot be cast to the QGraphicsObject.
My goal is to print the html content. I thank that a first way was to create a QImage from the WebView but maybe there is a simplest way.
Does anyone have a suggestion ?
Thanks in advance,
jalomic last edited by jalomic
You can cast your webview to QQuickPaintedItem ( because QQuickWebView iherits it), it has paint(QPainter *) method. Just replace QPainter and call this function !
Hi Jalomic and thanks for you reply.
I have tried your way but without sucess.
- The webview cannot be cast to QQuickPaintedItem
- The webvies can be cast to QQuickWebView but:
- I need then to include webkit-private and qquick-private to my .pro
- the QQuickWebView inherit from QQuickFlickable then QQuickItem but no QQuickPaintedItem
- There is no paint method for QQuickWebView
jalomic last edited by
jalomic last edited by
@mperrinel It is very ruefully :(
Thanks for the link. I have read it.
It's very nice and can probably answer most of the case. But because it only works with a subset of QtQuickItem like image or text, I think that will not be enough for the webview. The biggest problem of the webview is it content height that can be very huge.
The grabImage was a nice way, but I was blocked by a problem of memory. only about the first 2000 height was painted...