PyQt4 和 QtWebKit - 如何自动滚动视图?

发布于 2024-07-15 19:27:11 字数 278 浏览 6 评论 0原文

我在 PyQt 应用程序窗口中有一个 QtWebKit.QWebView 小部件,我用它来显示类似聊天的应用程序的文本和内容。

    self.mainWindow = QtWebKit.QWebView()
    self.mainWindow.setHtml(self._html)

随着对话变长,会出现垂直滚动条。

我想要得到的是在需要时将显示的视图滚动到底部。 我该怎么做? 或者,也许我不应该为此使用 QWebView 小部件?

I got a QtWebKit.QWebView widget in a PyQt application window that I use to display text and stuff for a chat-like application.

    self.mainWindow = QtWebKit.QWebView()
    self.mainWindow.setHtml(self._html)

As the conversation gets longer the vertical scrollbar appears.

What I'd like to get, is to scroll the displayed view to the bottom when it's needed. How can I do it? Or, maybe, I shouldn't use QWebView widget for this?

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

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

发布评论

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

评论(3

薄暮涼年 2024-07-22 19:27:11

对于 (Py)Qt 4.5,使用框架的滚动位置,例如 self._html.page().mainFrame().setScrollPosition。 请参阅 QWebFrame::setScrollPosition() 函数。

For (Py)Qt 4.5, use frame's scroll position, e.g. self._html.page().mainFrame().setScrollPosition. See QWebFrame::setScrollPosition() function..

以往的大感动 2024-07-22 19:27:11

kender - QWebView 由 QWebPage 和 QWebFrame 组成。 滚动条属性存储在QWebFrame中,它有一个setScrollBarValue()方法,以及一个返回最大位置的scrollBarMaximum()方法。

请参阅这些链接了解详细信息:
QWebView,
QWebFrame

kender - The QWebView is made up of a QWebPage and a QWebFrame. The scroll bar properties are stored in the QWebFrame, which has a setScrollBarValue() method, as well as a scrollBarMaximum() method to return the max position.

See these links for details:
QWebView,
QWebFrame

琉璃繁缕 2024-07-22 19:27:11

也许JavaScript是最简单的方法,但您也可以使用QWebViewevaluateJavaScript函数:

self.page().mainFrame().evaluateJavaScript("window.scrollTo(0, "+str(self.init_ypos)+");")

其中self是一个类Browser(QWebView)self.mainWindow 适合您)。

Maybe JavaScript is the easiest way, but you may also use evaluateJavaScript function of QWebView:

self.page().mainFrame().evaluateJavaScript("window.scrollTo(0, "+str(self.init_ypos)+");")

where self is a class Browser(QWebView) (self.mainWindow for you).

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