将Qwebengineviewer scrollbar设置在页面底部

发布于 2025-02-14 01:18:34 字数 449 浏览 0 评论 0原文

我在QMainWindow中使用了Qwebengineviewer窗口小部件,我希望每次打开应用程序时,它总是在页面的botom上都有滚动条。我发现了一些建议,但它们似乎对我有用。例如,我找到了一个适合的答案

self.webEngine.page().runJavaScript("window.scrollTo(0, 0);")

。我在qwebengineviewer中找不到它(我很确定这是从以前的QT版本中找到的)。这是C ++中提供的示例:

webView->page()->mainFrame()->setScrollBarValue(Qt::Vertical, webView->page()->mainFrame()->scrollBarMaximum(Qt::Vertical));

事先感谢您的帮助!

I'm using a QWebEngineViewer widget in my QMainWindow and I want it to have the scrollbar always at the botom of the page every time I open my application. I have found some suggestions but none of them seem to work for me. For example, a posible answer i found used .runJavaScript() to modify de scrollbar position from there, but no matter what I but in the x or y axis the scrollbar doesn't move:

self.webEngine.page().runJavaScript("window.scrollTo(0, 0);")

Another suggestion used the setScrollBarValue() function, but I can't find it in QWebEngineViewer (I'm pretty sure that is from a previous version of qt). Here is the example provided in C++:

webView->page()->mainFrame()->setScrollBarValue(Qt::Vertical, webView->page()->mainFrame()->scrollBarMaximum(Qt::Vertical));

Thanks in advance for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

莳間冲淡了誓言ζ 2025-02-21 01:18:34

这是我为解决问题所做的。首先,我实现了如下:

    def scrollDown(self):
        self.webEngine.page().runJavaScript("window.scrollTo(0, document.body.scrollHeight);") 

document.body.scrollheight有助于在页面底部找到滚动条。

然后,我将scrolldown连接到了加载信号:

self.webEngine.loadFinished.connect(self.scrollDown)

谢谢@musicamante的建议!

Here is what I did to solve the problem. First I implemented scrollDown as follows:

    def scrollDown(self):
        self.webEngine.page().runJavaScript("window.scrollTo(0, document.body.scrollHeight);") 

document.body.scrollHeight helps in locating the scrollbar at the bottom of the page.

Then I connected scrollDown to the loadFinished signal:

self.webEngine.loadFinished.connect(self.scrollDown)

Thanks @musicamante for the suggestion!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文