Bokambo
Bokambo

Reputation: 4480

Finger Scrolling in QT?

I have implemented Finger Scrolling to one of my QListWidget. I have taken refernce from http://www.developer.nokia.com/Community/Wiki/Qt_Kinetic_scrolling_-_from_idea_to_implementation

Now the problem is on_current_row_changed event of QListWidget gets fired when i scroll up and down my List. How i can avoid this on click only it should behave like click not on Scroll.

Upvotes: 2

Views: 4020

Answers (2)

svlasov
svlasov

Reputation: 10455

Starting from Qt5 this is as simple as:

#include <QScroller>
...
QScroller::grabGesture(myListWidget, QScroller::LeftMouseButtonGesture);

For touch screens use TouchGesture instead of LeftMouseButtonGesture.

If the widget doesn't inherit QAbstractScrollArea (e.g. QWebView):

QScrollArea *scrollArea = new QScrollArea;
scrollArea->setWidget(myWidget);
QScroller::grabGesture(scrollArea, QScroller::LeftMouseButtonGesture);

Be sure to resize the widget to its content size.

Upvotes: 8

sam-w
sam-w

Reputation: 7687

You need to test whether the finger has moved between mousePress and mouseRelease. You can extract the position of the press, so if you store it in an intermediate variable, then test it against the position of the mouseRelease (say using QPoint::manhattanLength()), you can tell whether the finger has moved. If it has, the user is scrolling, if not, they're clicking.

EDIT: Looking at the code you've linked to, they're already doing the above. Could we see some more of your reimplemenation?

Upvotes: 1

Related Questions