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. QGraphicsView touch zoom
Qt 6.11 is out! See what's new in the release blog

QGraphicsView touch zoom

Scheduled Pinned Locked Moved Unsolved General and Desktop
20 Posts 3 Posters 4.6k Views 1 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.
  • NiagarerN Niagarer

    0_1548411528396_Qt1.png

    @jsulm
    normal, via maintance tool...

    strange. I will try tomorrow on my desk, I am on my notebook right now.

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #7

    @Niagarer You can open the examples by navigating to them from File menu

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    NiagarerN 1 Reply Last reply
    0
    • jsulmJ jsulm

      @Niagarer You can open the examples by navigating to them from File menu

      NiagarerN Offline
      NiagarerN Offline
      Niagarer
      wrote on last edited by Niagarer
      #8

      @jsulm
      I even can't find it on my desk in Qt Creator.
      I navigated to the Qt5.12\Examples\Qt-5.12.0\widgets\touch\pinchzoom folder (so, it actually exists), but when running it manually (opening pinchzoom.pro) it just crashes... really trange, I didn't have any problems with Qt Creator so far. I'm sorry, that this is drifting away from the actual question

      mrjjM 1 Reply Last reply
      0
      • NiagarerN Niagarer

        @jsulm
        I even can't find it on my desk in Qt Creator.
        I navigated to the Qt5.12\Examples\Qt-5.12.0\widgets\touch\pinchzoom folder (so, it actually exists), but when running it manually (opening pinchzoom.pro) it just crashes... really trange, I didn't have any problems with Qt Creator so far. I'm sorry, that this is drifting away from the actual question

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #9

        @Niagarer
        Ok, i just tried the sample here. just ran but i have no touch.

        Try to set a break point in main.cpp and step over code to see what makes it crash.

        also set break point here

        bool GraphicsView::viewportEvent(QEvent *event)
        {
            switch (event->type()) {
            case QEvent::TouchBegin:
            case QEvent::TouchUpdate:
            case QEvent::TouchEnd:
            {
                QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
        

        and see if it crashes when processing touch events.

        NiagarerN 1 Reply Last reply
        0
        • mrjjM mrjj

          @Niagarer
          Ok, i just tried the sample here. just ran but i have no touch.

          Try to set a break point in main.cpp and step over code to see what makes it crash.

          also set break point here

          bool GraphicsView::viewportEvent(QEvent *event)
          {
              switch (event->type()) {
              case QEvent::TouchBegin:
              case QEvent::TouchUpdate:
              case QEvent::TouchEnd:
              {
                  QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
          

          and see if it crashes when processing touch events.

          NiagarerN Offline
          NiagarerN Offline
          Niagarer
          wrote on last edited by Niagarer
          #10

          @mrjj
          thank you, it works now -.-
          yesterday it just crashed, really strange (I didn't even recreated the project). Qt Creator seems to have bad days somethimes. Thanks anyway!

          The zoom works, but there is a problem. In the example, the transform of the view itself is just changed. But proxywidgets placed in the scene get scaled too when changing transform. What I need is some kind of scale that does not effect the scale of the proxys in the scene. The proxys shall always be in the same viewport position. How can I achieve both, scaling that way and fixed proxys?

          mrjjM 1 Reply Last reply
          0
          • NiagarerN Niagarer

            @mrjj
            thank you, it works now -.-
            yesterday it just crashed, really strange (I didn't even recreated the project). Qt Creator seems to have bad days somethimes. Thanks anyway!

            The zoom works, but there is a problem. In the example, the transform of the view itself is just changed. But proxywidgets placed in the scene get scaled too when changing transform. What I need is some kind of scale that does not effect the scale of the proxys in the scene. The proxys shall always be in the same viewport position. How can I achieve both, scaling that way and fixed proxys?

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #11

            Hi
            Ok. odd.
            i was wondering if
            QGraphicsItem::ItemIgnoresTransformations

            works QGraphicsProxyWidget

            NiagarerN 1 Reply Last reply
            1
            • mrjjM mrjj

              Hi
              Ok. odd.
              i was wondering if
              QGraphicsItem::ItemIgnoresTransformations

              works QGraphicsProxyWidget

              NiagarerN Offline
              NiagarerN Offline
              Niagarer
              wrote on last edited by
              #12

              @mrjj
              Thank you, this is a really useful one. It actually works just to say

              myProxy->ItemIgnoresTransformations;
              

              (is this really the right way to do it?)
              but when zooming, the proxy also gets scaled for a moment and then jumps back to it's old scale which looks really ugly :D

              mrjjM 1 Reply Last reply
              0
              • NiagarerN Niagarer

                @mrjj
                Thank you, this is a really useful one. It actually works just to say

                myProxy->ItemIgnoresTransformations;
                

                (is this really the right way to do it?)
                but when zooming, the proxy also gets scaled for a moment and then jumps back to it's old scale which looks really ugly :D

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #13

                @Niagarer

                ehh that look odd.
                If you press F2 on it what does it show ?
                Im not even sure what it is :) dont look like function call.

                Normally it set via
                http://doc.qt.io/qt-5/qgraphicsitem.html#setFlags

                NiagarerN 1 Reply Last reply
                1
                • mrjjM mrjj

                  @Niagarer

                  ehh that look odd.
                  If you press F2 on it what does it show ?
                  Im not even sure what it is :) dont look like function call.

                  Normally it set via
                  http://doc.qt.io/qt-5/qgraphicsitem.html#setFlags

                  NiagarerN Offline
                  NiagarerN Offline
                  Niagarer
                  wrote on last edited by
                  #14

                  @mrjj
                  Oh, I just realized, that the mouseWheelEvent also gets triggered, when zooming via touch (!?) and in the mouseWheelEvent I did some scaling on the proxy manually. I deleted that (because I don't even need the manual scaling when ignoring tranformations, so the tip was really useful) and now I can tell:

                  proxy->ItemIgnoresTransformations;
                  

                  doesn't work right (but it doesn't scale and jump back anymore now, my bad).

                  proxy->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
                  

                  works perfectly well.

                  mrjjM 1 Reply Last reply
                  1
                  • NiagarerN Niagarer

                    @mrjj
                    Oh, I just realized, that the mouseWheelEvent also gets triggered, when zooming via touch (!?) and in the mouseWheelEvent I did some scaling on the proxy manually. I deleted that (because I don't even need the manual scaling when ignoring tranformations, so the tip was really useful) and now I can tell:

                    proxy->ItemIgnoresTransformations;
                    

                    doesn't work right (but it doesn't scale and jump back anymore now, my bad).

                    proxy->setFlag(QGraphicsItem::ItemIgnoresTransformations, true);
                    

                    works perfectly well.

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #15

                    Hi
                    Super.
                    Im not even sure why proxy->ItemIgnoresTransformations;
                    can compile :)
                    Anyway the setFlag is the way to go as you also then dont overwrite any exiting flags.

                    NiagarerN 1 Reply Last reply
                    0
                    • mrjjM mrjj

                      Hi
                      Super.
                      Im not even sure why proxy->ItemIgnoresTransformations;
                      can compile :)
                      Anyway the setFlag is the way to go as you also then dont overwrite any exiting flags.

                      NiagarerN Offline
                      NiagarerN Offline
                      Niagarer
                      wrote on last edited by Niagarer
                      #16

                      @mrjj said in QGraphicsView touch zoom:

                      Im not even sure why proxy->ItemIgnoresTransformations;
                      can compile :)

                      Yes, it has been one of these moments

                      "this can surely not work, it's nonsense... but why not just hitting ctl+r"
                      <<program starts>>
                      "uuh, wait, what?!"

                      mrjjM 1 Reply Last reply
                      0
                      • NiagarerN Niagarer

                        @mrjj said in QGraphicsView touch zoom:

                        Im not even sure why proxy->ItemIgnoresTransformations;
                        can compile :)

                        Yes, it has been one of these moments

                        "this can surely not work, it's nonsense... but why not just hitting ctl+r"
                        <<program starts>>
                        "uuh, wait, what?!"

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #17

                        @Niagarer
                        Hi
                        Yes c++ is good at such moments :)
                        Just checked it - it reads like
                        proxy->GraphicsItemFlag::ItemIgnoresTransformations;
                        and compiler just sees
                        0x20;
                        which is perfectly valid and at same time complete nonsense :)
                        But hey - its valid so no complains :)

                        NiagarerN 1 Reply Last reply
                        1
                        • mrjjM mrjj

                          @Niagarer
                          Hi
                          Yes c++ is good at such moments :)
                          Just checked it - it reads like
                          proxy->GraphicsItemFlag::ItemIgnoresTransformations;
                          and compiler just sees
                          0x20;
                          which is perfectly valid and at same time complete nonsense :)
                          But hey - its valid so no complains :)

                          NiagarerN Offline
                          NiagarerN Offline
                          Niagarer
                          wrote on last edited by Niagarer
                          #18

                          I've got one more question on this.
                          I have custom selection procedure in my graphicsView like this

                          void GraphWidget::mouseMoveEvent(QMouseEvent *event){
                          
                              if(leftMousePressed && !itemAt(event->pos())){
                                  if(zooming){
                                      //pass
                                  }else{
                                      selectingMultipleNodes = true;
                                      // ...
                                  }
                          
                              QGraphicsView::mouseMoveEvent(event);
                          }
                          

                          selectingMultipleNodes obviously causes a selection of objects in the graph. But when I zoom, I don't want to select objects, so I added the zoom variable to it like

                          bool GraphWidget::viewportEvent(QEvent *event)
                          {
                              switch (event->type()) {
                              case QEvent::TouchBegin:
                              case QEvent::TouchUpdate:
                              case QEvent::TouchEnd:
                              {
                                  zooming = true;
                                  // ...
                                  if (touchPoints.count() == 2) {
                                      // ...
                                  }else{
                                      zooming = false;
                                  }
                                  return true;
                              }
                              default: break;
                              }
                              return QGraphicsView::viewportEvent(event);
                          }
                          

                          But when zooming via touch, almost always one finger touches the screen a little (recognizable) bit earlier that the other one. How is this normally handeled in Qt?

                          1 Reply Last reply
                          0
                          • mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #19

                            Hi
                            I think people use
                            http://doc.qt.io/qt-5/gestures-overview.html
                            but i have not used it myself since im always stuck with single point touch.
                            I do see the issue though.
                            Give it some hours and see if someone has a good way of fixing this as
                            gestures might be overkill :)

                            NiagarerN 1 Reply Last reply
                            0
                            • mrjjM mrjj

                              Hi
                              I think people use
                              http://doc.qt.io/qt-5/gestures-overview.html
                              but i have not used it myself since im always stuck with single point touch.
                              I do see the issue though.
                              Give it some hours and see if someone has a good way of fixing this as
                              gestures might be overkill :)

                              NiagarerN Offline
                              NiagarerN Offline
                              Niagarer
                              wrote on last edited by
                              #20

                              @mrjj
                              Hi, thanks for the tip.

                              I just implemented needed methods for the pinch gesture, but I still have the same problem. The gesture is just an event and the mousePressEvent still gets triggered too.
                              In the mousePressEvent I do plenty of important stuff, so I need to find a way of knowing in the mousePressEvent, weather a gesture is triggered at the same time (and ignore then) or something like that.
                              Does someone know a workaround or how this problem is typically handeled?

                              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