Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Only receiving Tap and TapAndHold gestures in QGraphicsObject

    General and Desktop
    1
    1
    61
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      Asperamanca last edited by

      I am trying to implement paging in a QGraphicsObject using the swipe gesture.
      First I enable gestures in my QGraphicsObject-derived class:

      grabGesture(Qt::SwipeGesture);
      enableGestureForViews(scene(),Qt::SwipeGesture);
      

      EnableGesturesForViews iterates through all views and enables the gesture for each:

      MyClass::enableGesturesForViews(QGraphicsScene* const pScene, const Qt::GestureType eGesture)
      {
          const auto& views = pScene->views();
          for(auto* const pView : views)
              {
                  enableGestureRecursive(pView, eGesture);
              }
      }
      
      MyClass::enableGestureRecursive(QWidget* const pWidget, const Qt::GestureType eGesture)
      {
          if (pWidget == nullptr)
          {
              return;
          }
          pWidget->grabGesture(eGesture);
          pWidget->setAttribute(Qt::WA_AcceptTouchEvents);
          enableGestureRecursive(pWidget->parentWidget(),eGesture);
      }
      

      As you can see, I take no chances. Since the docs isn't very specific where to enable what, I go up all the way to my top-level widget and enable both the gesture and touch.

      In my sceneEvent, I expect the QGestureEvent to arrive:

          if (event->type() == QEvent::Gesture)
          {
              if (handleGestureEvent(event))
              {
                  return true;
              }
          }
      

      The content of handleGestureEvent is irrelevant so far, as I never get there. No single gesture is recognized.

      When I enabled all gestures for testing, I did receive Tap and TapAndHold gestures, but neither Pan, Pinch nor Swipe.

      What am I doing wrong?

      1 Reply Last reply Reply Quote 0
      • First post
        Last post