I am trying to render html data to qimage or qpicture using QWebPage/QWebFrame without QWebView:
auto htmlData = R"(
<!DOCTYPE html>
<html>
<body>
<p>A quick brown fox jumps over the lazy dog.</p>
</body>
</html>
)";
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWebPage page;
auto frame = page.mainFrame();
frame->setContent(htmlData, "text/html");
QImage img(500, 500, QImage::Format_ARGB32);
QPainter p(&img);
frame->render(&p);
p.end();
img.save("html.png");
return 0;
}
The result image is blank and I can’t figure what else I need to do to make the html render properly. QWebFrame::print does produce correct PDF file though.
↧