Problems with Open-Source Downloads read and

Render html to image/qpicture

  • I am trying to render html data to qimage or qpicture using QWebPage/QWebFrame without QWebView:
    @auto htmlData = R"(
    <!DOCTYPE html>
    <p>A quick brown fox jumps over the lazy dog.</p>

    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);
    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.

  • OK. I finally figure it out. I need to call QWebPage::setViewportSize(). I guess it's automatically set if the page is part of QWebView.

Log in to reply