Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt WebKit
  4. Render html to image/qpicture
Forum Updated to NodeBB v4.3 + New Features

Render html to image/qpicture

Scheduled Pinned Locked Moved Qt WebKit
2 Posts 1 Posters 3.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stephenju
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stephenju
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved