Details
Description
Similar to https://bugreports.qt.io/browse/QTBUG-54172 when a view that has never been visible is asked to load a page with an anchor it may end up being scrolled to the wrong position when shown. Possibly `.resize()` doesn't end up flowing through to the renderer until it is first shown. Or something.
Here is a reproducer, on 5.12.4 the background tab scrolls to the expected place initially and thus the two window.scrollY numbers reported are the same. On 5.13 they are different and they should be more different if more content is added to the other element.
Showing the tab (and then hiding it again) before loading makes it work fine.
<html> <body style="height: 1200px"> <div id="spacer" style="height: 200px"></div> <div id="other"> <p>Other content</p> </div> <div id="anchor">Scroll to here</div> </body> </html>
#include <QWebEngineView> #include <QApplication> #include <QTabWidget> #include <QUrl> #include <QTimer> int main(int argc, char **argv) { QApplication app(argc, argv); int width = 400; int height = 600; QTabWidget tabs; tabs.resize(width, height); tabs.show(); QWebEngineView view; view.resize(width, height); tabs.insertTab(0, &view, QString("0")); QWebEngineView view2; view2.resize(width, height); tabs.insertTab(1, &view2, QString("1")); view.load(QUrl("file:///tmp/long.html?1#anchor")); view2.load(QUrl("file:///tmp/long.html?2#anchor")); tabs.setCurrentIndex(0); QTimer::singleShot(100, [&app, &tabs, &view2]() { tabs.setCurrentIndex(1); view2.page()->runJavaScript(QString("console.log(window.scrollY)")); view2.page()->runJavaScript(QString("document.getElementById('anchor').scrollIntoView()")); view2.page()->runJavaScript(QString("console.log(window.scrollY)")); }); return app.exec(); }
Attachments
Issue Links
- relates to
-
QTBUG-54172 WebEngineView fails to scroll to anchor when making it visible directly before calling setUrl
- Closed
-
QTBUG-79369 Check failed: GetDocument().Lifecycle().GetState() >= DocumentLifecycle::kAfterPerformLayout (4 vs. 9)
- Closed