Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 213
Dewsworld Avatar asked Apr 26 '12 14:04

Dewsworld


1 Answers

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");
like image 155
Emanuele Bezzi Avatar answered Oct 18 '22 01:10

Emanuele Bezzi