Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Really tight pinch-zoom-scroll on QGraphicsView?

Really tight pinch-zoom-scroll on QGraphicsView?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 2 Posters 1.6k Views 2 Watching
  • 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.
  • P Offline
    P Offline
    patrickkidd
    wrote on last edited by
    #1

    Hello! Has anyone ever seen a super tight two-fingered pinch-zoom-scroll gesture implementation on QGraphicsView? This is such an important gesture and I have never really seen it done very well in Qt with the graphics view framework.

    Thanks!

    https://alaskafamilysystems.com/

    1 Reply Last reply
    0
    • SeeLookS Offline
      SeeLookS Offline
      SeeLook
      wrote on last edited by SeeLook
      #2

      Hi @patrickkidd

      Here is a piece of code that zooms/scrolls my QGraphicsView well, but I don't know how is "really tight" measured so there is a variable reallyTight that covers that.

      bool MyGraphicsView::viewportEvent(QEvent* event) {
          if (event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchEnd) {
            QTouchEvent *te = static_cast<QTouchEvent*>(event);
            if (te->touchPoints().count() == 1) {
                // single touch routines
            } else if (te->touchPoints().count() == 2) {
              QLineF l1(te->touchPoints()[0].startPos(), te->touchPoints()[1].startPos()); // initial double-touch position
              QLineF l2(te->touchPoints()[0].pos(), te->touchPoints()[1].pos()); // final position
              qreal distance = l1.length() - l2.length();
              if (distance < -reallyTight) { 
                  // zoom out
              } else if (distance > reallyTight) { 
                  // zoom in
              } else if (distance < reallyTight * 0.75) // just scroll
                verticalScrollBar()->setValue(verticalScrollBar()->value() + int(te->touchPoints()[0].lastPos().y() - te->touchPoints()[0].pos().y()));
              return true;
            }
          }
        return QGraphicsView::viewportEvent(event);
      }
      

      I hope it may be sort of start point.

      P 1 Reply Last reply
      1
      • SeeLookS SeeLook

        Hi @patrickkidd

        Here is a piece of code that zooms/scrolls my QGraphicsView well, but I don't know how is "really tight" measured so there is a variable reallyTight that covers that.

        bool MyGraphicsView::viewportEvent(QEvent* event) {
            if (event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchEnd) {
              QTouchEvent *te = static_cast<QTouchEvent*>(event);
              if (te->touchPoints().count() == 1) {
                  // single touch routines
              } else if (te->touchPoints().count() == 2) {
                QLineF l1(te->touchPoints()[0].startPos(), te->touchPoints()[1].startPos()); // initial double-touch position
                QLineF l2(te->touchPoints()[0].pos(), te->touchPoints()[1].pos()); // final position
                qreal distance = l1.length() - l2.length();
                if (distance < -reallyTight) { 
                    // zoom out
                } else if (distance > reallyTight) { 
                    // zoom in
                } else if (distance < reallyTight * 0.75) // just scroll
                  verticalScrollBar()->setValue(verticalScrollBar()->value() + int(te->touchPoints()[0].lastPos().y() - te->touchPoints()[0].pos().y()));
                return true;
              }
            }
          return QGraphicsView::viewportEvent(event);
        }
        

        I hope it may be sort of start point.

        P Offline
        P Offline
        patrickkidd
        wrote on last edited by
        #3

        @SeeLook said in Really tight pinch-zoom-scroll on QGraphicsView?:

        Hi @patrickkidd

        Here is a piece of code that zooms/scrolls my QGraphicsView well, but I don't know how is "really tight" measured so there is a variable reallyTight that covers that.

        bool MyGraphicsView::viewportEvent(QEvent* event) {
            if (event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchEnd) {
              QTouchEvent *te = static_cast<QTouchEvent*>(event);
              if (te->touchPoints().count() == 1) {
                  // single touch routines
              } else if (te->touchPoints().count() == 2) {
                QLineF l1(te->touchPoints()[0].startPos(), te->touchPoints()[1].startPos()); // initial double-touch position
                QLineF l2(te->touchPoints()[0].pos(), te->touchPoints()[1].pos()); // final position
                qreal distance = l1.length() - l2.length();
                if (distance < -reallyTight) { 
                    // zoom out
                } else if (distance > reallyTight) { 
                    // zoom in
                } else if (distance < reallyTight * 0.75) // just scroll
                  verticalScrollBar()->setValue(verticalScrollBar()->value() + int(te->touchPoints()[0].lastPos().y() - te->touchPoints()[0].pos().y()));
                return true;
              }
            }
          return QGraphicsView::viewportEvent(event);
        }
        

        I hope it may be sort of start point.

        Thanks for that, I should have been more specific when I said "tight." I would like to implement the sort of simultaneous two-fingered zoom and scroll that is so common in iOS apps, for example when you are looking at a photo in the Photos app. You can pinch and zoom and scroll into any place on the photo, and it is perceptively almost perfectly "tight" in that it sticks to where your fingers are and is quite fast.

        https://alaskafamilysystems.com/

        SeeLookS 1 Reply Last reply
        1
        • P patrickkidd

          @SeeLook said in Really tight pinch-zoom-scroll on QGraphicsView?:

          Hi @patrickkidd

          Here is a piece of code that zooms/scrolls my QGraphicsView well, but I don't know how is "really tight" measured so there is a variable reallyTight that covers that.

          bool MyGraphicsView::viewportEvent(QEvent* event) {
              if (event->type() == QEvent::TouchBegin || event->type() == QEvent::TouchUpdate || event->type() == QEvent::TouchEnd) {
                QTouchEvent *te = static_cast<QTouchEvent*>(event);
                if (te->touchPoints().count() == 1) {
                    // single touch routines
                } else if (te->touchPoints().count() == 2) {
                  QLineF l1(te->touchPoints()[0].startPos(), te->touchPoints()[1].startPos()); // initial double-touch position
                  QLineF l2(te->touchPoints()[0].pos(), te->touchPoints()[1].pos()); // final position
                  qreal distance = l1.length() - l2.length();
                  if (distance < -reallyTight) { 
                      // zoom out
                  } else if (distance > reallyTight) { 
                      // zoom in
                  } else if (distance < reallyTight * 0.75) // just scroll
                    verticalScrollBar()->setValue(verticalScrollBar()->value() + int(te->touchPoints()[0].lastPos().y() - te->touchPoints()[0].pos().y()));
                  return true;
                }
              }
            return QGraphicsView::viewportEvent(event);
          }
          

          I hope it may be sort of start point.

          Thanks for that, I should have been more specific when I said "tight." I would like to implement the sort of simultaneous two-fingered zoom and scroll that is so common in iOS apps, for example when you are looking at a photo in the Photos app. You can pinch and zoom and scroll into any place on the photo, and it is perceptively almost perfectly "tight" in that it sticks to where your fingers are and is quite fast.

          SeeLookS Offline
          SeeLookS Offline
          SeeLook
          wrote on last edited by
          #4

          @patrickkidd
          I've never used it so far but I believe this piece of code could be extended easily to achieve such gesture.

          1 Reply Last reply
          0

          • Login

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