Advertisement
Guest User

Untitled

a guest
Mar 26th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. NewsFeedPost::NewsFeedPost(QGraphicsItem *parent) : MWidget(parent)
  2. {
  3.     setAcceptTouchEvents(true);
  4.     grabGesture(Qt::SwipeGesture);
  5. }
  6.  
  7. bool NewsFeedPost::event(QEvent *event)
  8. {
  9.     if (event->type() == QEvent::Gesture) {
  10.         gestureEvent(static_cast<QGestureEvent*>(event));
  11.         return true;
  12.     }
  13.     return MWidget::event(event);
  14. }
  15.  
  16. void NewsFeedPost::gestureEvent(QGestureEvent *ev)
  17. {
  18.     if (QGesture *gesture = ev->gesture(Qt::SwipeGesture)) {
  19.         QSwipeGesture *swipe = static_cast<QSwipeGesture*>(gesture);
  20.         if (swipe->verticalDirection() == QSwipeGesture::Up) {
  21.             qDebug() << "Swiped to right";
  22.         }
  23.         else if (swipe->verticalDirection() == QSwipeGesture::Down) {
  24.             qDebug() << "Swiped to left";
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement