Dewsworld
Dewsworld

Reputation: 14033

How to get pictures from QWebView

Does anybody know how to get a picture from qwebview? My situation is, there is no scope to use the image url and then a QNetworkRequest. I just need to 'extract' the image from the QWebview.

Upvotes: 6

Views: 3514

Answers (1)

Emanuele Bezzi
Emanuele Bezzi

Reputation: 1728

First you need to get the QWebElement with the image you want to save - if you don't have it already, a good way to get it is

QWebElement el = view.page()->mainFrame()->findFirstElement("IMG[src='path/to/img'");

assuming view is the name of your QWebView. Then,

QImage image(el.geometry().width(), el.geometry().height(), QImage::Format_ARGB32);
QPainter painter(&image);
el.render(&painter);
painter.end();
image.save("path/to/img.png");

Upvotes: 11

Related Questions