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?
QtWS25 Last Chance

Really tight pinch-zoom-scroll on QGraphicsView?

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
4 Posts 2 Posters 1.4k 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.
  • P Offline
    P Offline
    patrickkidd
    wrote on 16 Jul 2017, 01:35 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
    • S Offline
      S Offline
      SeeLook
      wrote on 17 Jul 2017, 19:11 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 25 Jul 2017, 01:15
      1
      • S SeeLook
        17 Jul 2017, 19:11

        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 25 Jul 2017, 01:15 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/

        S 1 Reply Last reply 25 Jul 2017, 12:49
        1
        • P patrickkidd
          25 Jul 2017, 01:15

          @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.

          S Offline
          S Offline
          SeeLook
          wrote on 25 Jul 2017, 12:49 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