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 render WebEngineView correctly after scrolling?
Qt 6.11 is out! See what's new in the release blog

How to render WebEngineView correctly after scrolling?

Scheduled Pinned Locked Moved Unsolved QtWebEngine
1 Posts 1 Posters 1.5k Views
  • 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Saving an image of a webpage with a WebEngineView works fine, but when I want to scroll and save another image, the resulting image does not show the website has been scrolled (it shows the top of the webpage).

    My question is: how do I scroll down in the QWebEngineView then save a screen shot that shows the correctly scrolled webpage?

    I take a screenshot at the top of the webpage, scroll down ~700 pixels, wait for a javascript callback to trigger which then takes another screenshot. The javascript and callback works fine (I observe the QWebEngineView scrolling).

    this->setScrollPageHandlerFunc([&] (const QVariant &result) {
        saveSnapshotScroll();
    });
    saveSnapshotScroll();
    view->page()->runJavaScript("scrollPage();",this->scrollPageHandlerFunc);
    

    Screenshot code:

    void MainWindow::saveSnapshotScroll()
    {
    
    QPixmap pixmap(this->size());
    view->page()->view()->render(&pixmap);
    pixmap.save(QString::number(QDateTime::currentMSecsSinceEpoch()) + ".png");
    
    }
    

    Javascript:

    function scrollPage()
    {
        var y = qt_jq.jQuery(window).scrollTop();
        qt_jq.jQuery(window).scrollTop(y+708);
    }
    
    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