kender
kender

Reputation: 87131

PyQt4 and QtWebKit - how to auto scroll the view?

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?

Upvotes: 0

Views: 2985

Answers (3)

Jason Coon
Jason Coon

Reputation: 18421

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

Upvotes: 1

A. STEFANI
A. STEFANI

Reputation: 6737

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

Upvotes: 0

Ariya Hidayat
Ariya Hidayat

Reputation: 12561

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

Upvotes: 3

Related Questions