×
Namespaces

Variants
Actions

Smooth scrolling in QWebView on Maemo 5

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Code Example
Source file: Media:Webkit2.zip
Compatibility
Platform(s):
Symbian
Article
Created: divanov (20 Apr 2010)
Last edited: hamishwillee (11 Oct 2012)

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

This page was last modified on 11 October 2012, at 04:18.
64 page views in the last 30 days.
×