Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QtWebEngine
  4. How to take screen captures
Forum Updated to NodeBB v4.3 + New Features

How to take screen captures

Scheduled Pinned Locked Moved Unsolved QtWebEngine
5 Posts 4 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.
  • R Offline
    R Offline
    rmam
    wrote on last edited by
    #1

    I would like to use Qt's QWebEngine module to take screen captures from an URL. However, although the documentation section on QWebEnginePage lists QWebEnginePage::print and 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?

    JonBJ 1 Reply Last reply
    0
    • R rmam

      I would like to use Qt's QWebEngine module to take screen captures from an URL. However, although the documentation section on QWebEnginePage lists QWebEnginePage::print and 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?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @rmam
      I would not have thought so. Though I could be wrong. :)

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mpergand
        wrote on last edited by
        #3

        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.

        R 1 Reply Last reply
        2
        • M mpergand

          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.

          R Offline
          R Offline
          rmam
          wrote on last edited by
          #4

          @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?

          1 Reply Last reply
          0
          • W Offline
            W Offline
            wolfgangr
            wrote on last edited by
            #5

            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.

            Snippet:

            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.

            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