⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)
How to take screen captures
rmam last edited by
I would like to use Qt's QWebEngine module to take screen captures from an URL. However, although the documentation section on
QWebEnginePage::printToPdf, it doesn't mention any way to save pages to image files.
Does anyone know if Qt's QWebEngine module can be used to take screen captures of websites?
JonB last edited by JonB
I would not have thought so.Though I could be wrong. :)
mpergand last edited by
You need to render the webEngineView:
QSize size(1024,800); view.resize(size); QImage image(size, QImage::Format_ARGB32); QPainter painter(&image); view->render(&painter); // render the webEngineView painter.end();
From my experience, the raw result is not very good, need a blurr effect.
rmam last edited by
@mpergand thanks for the help. I've managed to get a minimal working example to run based on your code snippet.
However, it appears that this approach involves creating a window. Is it possible to take a screenshot without opening a window?
wolfgangr last edited by
Does anyone have a suggestion?
I have the very same problem: How do I render a QWebEngineView that has received content via QWebEngineView::setHtml().
I do not want to show the Widget.
QImage img(region_width, region_height, QImage::Format_ARGB32); QWebEngineView* webEngineView = new QWebEngineView(); webEngineView->resize(region_width, region_height); webEngineView->setStyleSheet("background:red"); QWebEnginePage* webEnginePage = webEngineView->page(); webEnginePage->settings()>setAttribute(QWebEngineSettings::ScreenCaptureEnabled, true); webEngineView->setHtml("<p style=\"background-color:#FFF067;color:green\"> TEXT</p>"); QPainter p(&img); webEngineView->render(&p, QPoint(0, 0), QRegion(regionSize)); p.end(); img.save("img.png", "PNG", 80);
The result is always an entirely white image, regardless of the given background color, the
<p>does not get rendered.