Qt Reference Documentation

Maemo 5 QWebView Example

Files:

The Maemo 5 QWebView example shows how to switch user interaction from scrolling to text selection while using a swiping gesture.

By default, QWebView selects text when the user presses, holds and moves his or her finger. However, this behavior is not always wanted, since it clashes with kinetic finger scrolling.

In order to suppress text selection, this example introduces a helper class, QWebViewSelectionSuppressor. The class is standalone, so the header file qwebviewselectionsuppressor.h can be copied and used in any project.

         suppressor = new QWebViewSelectionSuppressor(view);

In order to use the helper class, it must be instantiated with a QWebView as parent. The QWebView becomes the parent of the helper class, which means that the suppressor does not have to be manually deleted. Once the class is instantiated, it registers an event filter on the QWebView and automatically suppresses text selection.

The QWebViewSelectionSuppressor class can be enabled and disabled on the fly:

             suppressor->disable();
             view->property("kineticScroller").value<QAbstractKineticScroller *>()->setEnabled(false);

In order to allow the user to select text when swiping with his/her finger, the suppressor must first be disabled. In addition, the kinetic scroller is also disabled to prevent the Web page from scrolling while the user selects text.

             suppressor->enable();
             view->property("kineticScroller").value<QAbstractKineticScroller *>()->setEnabled(true);

This code restores the old behavior by enabling the suppressor as well as the kinetic scroller. When the user is swiping with his/her finger, the view scrolls without selecting text.

X

Thank you for giving your feedback.

Make sure it is related to this specific page. For more general bugs and requests, please use the Qt Bug Tracker.

[0]; s.parentNode.insertBefore(ga, s); })();