PDA

View Full Version : Scrolling with gestures



woodtluk
28th September 2010, 17:29
I'v a custom Widget class and try to scroll with a gesture:



MyWidget::MyWidget(QWidget *parent) :
QWidget(parent) {

grabGesture(Qt::SwipeGesture);
}

bool MyWidget::event ( QEvent * event ) {
if (event->type() == QEvent::Gesture)
return gestureEvent(static_cast<QGestureEvent*>(event));

return QWidget::event(event);
}

bool MyWidget::gestureEvent ( QGestureEvent * event ) {
if (QGesture *swipe = event->gesture(Qt::SwipeGesture)) {
QSwipeGesture * swipeGesture = static_cast<QSwipeGesture *>(swipe);

int scrollFactor = 10;
if(swipeGesture->verticalDirection() == QSwipeGesture::Down)
scrollFactor = -scrollFactor;

if(swipeGesture->state() == Qt::GestureUpdated)
scroll(0, scrollFactor);


}
return true;
}

But I never get a gesture event.
Tried on Windows and on Symbian.

What's gonig on?

Thx!!!

wysota
29th September 2010, 10:24
Does your device support multi-touch? In Qt 4.6 gestures are only available for multi-touch devices.

woodtluk
29th September 2010, 12:39
It's a Nokia N8 and it supports multi-touch...

Thanks...

ashvindh
30th September 2010, 16:58
Hi,
Same problem i am trying to listen for gesture events on QGraphicsItem custom class
class TextItem : public QGraphicsTextItem
{
public:
TextItem(QGraphicsTextItem* parent = 0 ) : QGraphicsTextItem(parent)
{
grabGesture(Qt::SwipeGesture);
}

bool sceneEvent (QEvent* event);
bool gestureEvent(QGestureEvent* event);
void swipeTriggered(QSwipeGesture* gesture);
};

Only sceneEvent is generated but no gestrue event caught, using 4.7 on win xp.

What must be the problem??

Thanks
Asvindh R

wysota
30th September 2010, 17:47
Do you have a multitouch screen with proper drivers installed in your system? As far as I remember Windows XP doesn't have built-in support for reporting multi-touch events.