How to render WebEngineView correctly after scrolling?
Unsolved
QtWebEngine
-
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); }