Smooth scrolling in QWebView on Maemo 5
Article Metadata
Code Example
Article
Contents |
Overview
This article shows how to only scroll items on a QWebView without selecting the text.
Problem description
At the moment, finger scrolling on a QWebView does two things at the same time - scrolling and selecting text. The purpose of this article is to provide a workaround for this issue.
Solution
In order to only scroll a QWebView without selecting text, an event filter can be installed on the QWebViewobject. An event filter is an object that receives all events that are sent to the object. The filter can either stop the event or forward it to the object.
view->installEventFilter(this);
And then cancel mouse move events, when left button is pressed
bool QWebViewSelectionSuppressor::eventFilter(QObject *, QEvent *e)
{
switch (e->type()) {
case QEvent::MouseButtonPress:
if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
mousePressed = true;
break;
case QEvent::MouseButtonRelease:
if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
mousePressed = false;
break;
case QEvent::MouseMove:
if (mousePressed)
return true;
break;
default:
break;
}
return false;
}
The event filter filterObj receives events via its eventFilter() function. The eventFilter() function must return true if the event should be filtered, (i.e. stopped); otherwise it must return false.
Note that this is a temporary workaround until the QtWebKit bug 36109 is resolved.
Source Code
Small test application demonstrating the workaround File:Webkit2.zip


(no comments yet)