Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to implement Panning/Zooming in QGraphicsScene with two finger gestures on laptop trackpad (win/mac)?
Forum Update on Monday, May 27th 2025

How to implement Panning/Zooming in QGraphicsScene with two finger gestures on laptop trackpad (win/mac)?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 1.2k Views
  • 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.
  • S Offline
    S Offline
    stefanwoe
    wrote on last edited by stefanwoe
    #1

    I have a Qt 6.2 Application (Windows/Mac) using QGraphicsScene and want to use 2 fingers on the touch pad of my laptop for panning - as many other applications do.

    Zooming in/out works fine, but using 2 fingers for panning always results in zoom out.

    I found a number of questions and some fragmentary samples. But no half way complete example:

    https://stackoverflow.com/questions/8089838/finger-scrolling-in-qgraphicsview-in-qt
    https://forum.qt.io/topic/119221/how-to-listen-to-qtouchevent-originating-from-a-precision-touch-pad
    https://doc.qt.io/qt-5/gestures-overview.html]([link url](link url))
    

    What is the right way to do this?

    What i tried so far (on Windows):

    MyGraphicsView::MyGraphicsView(...) : QGraphicsView()
    {
        viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
    
    ...
    bool MyGraphicsView::viewportEvent ( QEvent * event )
    {
         switch (event->type())
        {
        case QEvent::TouchBegin:
        case QEvent::TouchUpdate:
        case QEvent::TouchEnd:
            {
            // never called
            }
    
    MyDocWin::MyDocWin(...) : CMDIAppDocWin(),
    {
        setAttribute(Qt::WA_AcceptTouchEvents);
    ...
    bool MyDocWin::event(QEvent *event)
    {
        switch (event->type())
        {
        case QEvent::TouchBegin:
        case QEvent::TouchUpdate:
        case QEvent::TouchEnd:
            {
                // never called
            }
    ...
    
    std::vector<Qt::GestureType> sgGestureTypes = {Qt::TapGesture, Qt::TapAndHoldGesture,Qt::PanGesture       ,Qt::PinchGesture     ,Qt::SwipeGesture         };
        
        
        MyGraphicsView::MyGraphicsView(...) : QGraphicsView()
        {
           for(Qt::GestureType gesture : sgGestureTypes)
                grabGesture(gesture);
        ...
        bool MyGraphicsView::event(QEvent *event)
        {
          switch (event->type())
            {
            case QEvent::Gesture:
            case QEvent::NativeGesture:
                        // never called
    
    4)
      
    [MyDocWin::MyDocWin(...) : CMDIAppDocWin(),
        {
        for (Qt::GestureType gesture : sgGestureTypes)
            grabGesture(gesture);
    ...
        bool MyDocWin::event(QEvent *event)
        {
            switch (event->type())
            {
            case QEvent::Gesture:
            case QEvent::NativeGesture:
                    // never called]([link url](link url))
    

    I already posted this on SO: https://stackoverflow.com/questions/70037430/how-to-pan-in-qgraphicsscene-with-two-fingers-on-laptop-trackpad

    S 1 Reply Last reply
    0
    • S stefanwoe

      I have a Qt 6.2 Application (Windows/Mac) using QGraphicsScene and want to use 2 fingers on the touch pad of my laptop for panning - as many other applications do.

      Zooming in/out works fine, but using 2 fingers for panning always results in zoom out.

      I found a number of questions and some fragmentary samples. But no half way complete example:

      https://stackoverflow.com/questions/8089838/finger-scrolling-in-qgraphicsview-in-qt
      https://forum.qt.io/topic/119221/how-to-listen-to-qtouchevent-originating-from-a-precision-touch-pad
      https://doc.qt.io/qt-5/gestures-overview.html]([link url](link url))
      

      What is the right way to do this?

      What i tried so far (on Windows):

      MyGraphicsView::MyGraphicsView(...) : QGraphicsView()
      {
          viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
      
      ...
      bool MyGraphicsView::viewportEvent ( QEvent * event )
      {
           switch (event->type())
          {
          case QEvent::TouchBegin:
          case QEvent::TouchUpdate:
          case QEvent::TouchEnd:
              {
              // never called
              }
      
      MyDocWin::MyDocWin(...) : CMDIAppDocWin(),
      {
          setAttribute(Qt::WA_AcceptTouchEvents);
      ...
      bool MyDocWin::event(QEvent *event)
      {
          switch (event->type())
          {
          case QEvent::TouchBegin:
          case QEvent::TouchUpdate:
          case QEvent::TouchEnd:
              {
                  // never called
              }
      ...
      
      std::vector<Qt::GestureType> sgGestureTypes = {Qt::TapGesture, Qt::TapAndHoldGesture,Qt::PanGesture       ,Qt::PinchGesture     ,Qt::SwipeGesture         };
          
          
          MyGraphicsView::MyGraphicsView(...) : QGraphicsView()
          {
             for(Qt::GestureType gesture : sgGestureTypes)
                  grabGesture(gesture);
          ...
          bool MyGraphicsView::event(QEvent *event)
          {
            switch (event->type())
              {
              case QEvent::Gesture:
              case QEvent::NativeGesture:
                          // never called
      
      4)
        
      [MyDocWin::MyDocWin(...) : CMDIAppDocWin(),
          {
          for (Qt::GestureType gesture : sgGestureTypes)
              grabGesture(gesture);
      ...
          bool MyDocWin::event(QEvent *event)
          {
              switch (event->type())
              {
              case QEvent::Gesture:
              case QEvent::NativeGesture:
                      // never called]([link url](link url))
      

      I already posted this on SO: https://stackoverflow.com/questions/70037430/how-to-pan-in-qgraphicsscene-with-two-fingers-on-laptop-trackpad

      S Offline
      S Offline
      stefanwoe
      wrote on last edited by
      #3

      I finaly found out how to handle this. See the SO post at https://stackoverflow.com/questions/70037430/qt-how-to-implement-panning-in-qgraphicsscene-with-two-fingers-on-laptop-trackp/70263559#70263559

      1 Reply Last reply
      2
      • JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by JoeCFD
        #2

        Touchpad gesture support for Wayland has landed in the Qt framework. This will be released as Qt 6.2.
        Touchpad gesture support for X server on Qt framework has been submitted for review.
        if you use 6.2 on Wayland, your code may work.
        https://bill.harding.blog/2021/06/06/linux-touchpad-like-macbook-update-touchpad-gestures-land-to-qt-gimp-and-x-server/

        1 Reply Last reply
        0
        • S stefanwoe

          I have a Qt 6.2 Application (Windows/Mac) using QGraphicsScene and want to use 2 fingers on the touch pad of my laptop for panning - as many other applications do.

          Zooming in/out works fine, but using 2 fingers for panning always results in zoom out.

          I found a number of questions and some fragmentary samples. But no half way complete example:

          https://stackoverflow.com/questions/8089838/finger-scrolling-in-qgraphicsview-in-qt
          https://forum.qt.io/topic/119221/how-to-listen-to-qtouchevent-originating-from-a-precision-touch-pad
          https://doc.qt.io/qt-5/gestures-overview.html]([link url](link url))
          

          What is the right way to do this?

          What i tried so far (on Windows):

          MyGraphicsView::MyGraphicsView(...) : QGraphicsView()
          {
              viewport()->setAttribute(Qt::WA_AcceptTouchEvents);
          
          ...
          bool MyGraphicsView::viewportEvent ( QEvent * event )
          {
               switch (event->type())
              {
              case QEvent::TouchBegin:
              case QEvent::TouchUpdate:
              case QEvent::TouchEnd:
                  {
                  // never called
                  }
          
          MyDocWin::MyDocWin(...) : CMDIAppDocWin(),
          {
              setAttribute(Qt::WA_AcceptTouchEvents);
          ...
          bool MyDocWin::event(QEvent *event)
          {
              switch (event->type())
              {
              case QEvent::TouchBegin:
              case QEvent::TouchUpdate:
              case QEvent::TouchEnd:
                  {
                      // never called
                  }
          ...
          
          std::vector<Qt::GestureType> sgGestureTypes = {Qt::TapGesture, Qt::TapAndHoldGesture,Qt::PanGesture       ,Qt::PinchGesture     ,Qt::SwipeGesture         };
              
              
              MyGraphicsView::MyGraphicsView(...) : QGraphicsView()
              {
                 for(Qt::GestureType gesture : sgGestureTypes)
                      grabGesture(gesture);
              ...
              bool MyGraphicsView::event(QEvent *event)
              {
                switch (event->type())
                  {
                  case QEvent::Gesture:
                  case QEvent::NativeGesture:
                              // never called
          
          4)
            
          [MyDocWin::MyDocWin(...) : CMDIAppDocWin(),
              {
              for (Qt::GestureType gesture : sgGestureTypes)
                  grabGesture(gesture);
          ...
              bool MyDocWin::event(QEvent *event)
              {
                  switch (event->type())
                  {
                  case QEvent::Gesture:
                  case QEvent::NativeGesture:
                          // never called]([link url](link url))
          

          I already posted this on SO: https://stackoverflow.com/questions/70037430/how-to-pan-in-qgraphicsscene-with-two-fingers-on-laptop-trackpad

          S Offline
          S Offline
          stefanwoe
          wrote on last edited by
          #3

          I finaly found out how to handle this. See the SO post at https://stackoverflow.com/questions/70037430/qt-how-to-implement-panning-in-qgraphicsscene-with-two-fingers-on-laptop-trackp/70263559#70263559

          1 Reply Last reply
          2

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved