6

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.

Dewsworld
  • 13,367
  • 23
  • 68
  • 104
  • What do you mean with "get a picture"? Getting a screenshot of the page? A screenshot of a portion of the page? Downloading an image contained in the DOM? – Emanuele Bezzi Apr 26 '12 at 15:14
  • I want to get an image which is in the view. For example, the image of This image without redownloading it, just from the view. If it don't work, then screenshot of a portion will do. – Dewsworld Apr 27 '12 at 07:41

1 Answers1

11

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");
Emanuele Bezzi
  • 1,708
  • 14
  • 15
  • 2
    `el.geometry().width(), el.geometry().height()` could be replaced with `el.geometry().size()` – Grief Oct 28 '16 at 19:12