Advertisement
Guest User

How ensure QWebEngineView is fully rendered

a guest
May 24th, 2019
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include <QApplication>
  2. #include <QPrinter>
  3. #include <QWebEngineProfile>
  4. #include <QWebEngineView>
  5. #include <iostream>
  6.  
  7. auto html =  "<!DOCTYPE html>"
  8. "<html lang=\"en\">"
  9. "<head>"
  10. "  <meta charset=\"UTF-8\">"
  11. "  <style>"
  12. "  img { max-width:100%; max-height:100%; }"
  13. "  div { height: 270px; width: 540px; }"
  14. "  body { margin: 0; background-color: red; }"
  15. "  </style>"
  16. "</head>"
  17. "<body>"
  18. "<div>"
  19. "  <img src=\"https://eoimages.gsfc.nasa.gov/images/imagerecords/73000/73751/world.topo.bathy.200407.3x5400x2700.png\">"
  20. "</div>"
  21. "</body>"
  22. "</html>"
  23. ;
  24.  
  25. int main(int argc, char *argv[])
  26. {
  27.     QApplication app(argc, argv);
  28.  
  29.     QWebEngineView view;
  30.     view.show();
  31.     view.resize(540, 270);
  32.  
  33.     QObject::connect(&view, &QWebEngineView::loadFinished, [&view](bool isOk) {
  34.        if (!isOk) {
  35.          std::cout << "Error";
  36.           return;
  37.        }
  38.         view.grab().save("page.png", "PNG");
  39.         view.close();
  40.     });
  41.  
  42.     view.setHtml(html);
  43.  
  44.     return app.exec();
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement