Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

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).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top