WebView and panning support

In some circumstances, for example on touch screen, a QtWebKit-based browser might not want to display the scroll bars. The reason does make sense, let the user pan around with the stylus or finger. In order to do that, scrolling the QWebView must be possible, even when the scroll bars are invisible.

The example below illustrates something a bit more than that. Not only the scroll bars are hidden, the user can actually use the mouse drag to pan around. In the touch screen devices, this translates to panning using the finger/stylus. The interesting part of the code is probably the use of JavaScript window.scrollX and window.scrollY to get the current scroll offset, and the function window.scrollTo to set the scroll offset, by using the wonderful QWebFrame::evaluateJavaScript. The rest of the panning logic is implemented by properly responding to the mouse events.

svn checkout svn://

Note: For Qt 4.5 we will have QWebFrame::scrollOffset and QWebFrame::setScrollOffset that can do the magic without the need to execute that piece of JavaScript code.

Blog Topics: