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 & QGraphicsScene movement with Zoomin & Zoom out, How to create map movement like google map?
Forum Updated to NodeBB v4.3 + New Features

QGraphicsview & QGraphicsScene movement with Zoomin & Zoom out, How to create map movement like google map?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 7.1k 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.
  • M Offline
    M Offline
    MyQT
    wrote on last edited by
    #1

    Hi,

    I have implemented map by using QGraphicsView & QGraphicsScene.
    Now I want to implement Zoomin & Zoonout with map movement.

    For Zoomin/ Zoom out I have used below function, it is working quite good.
    @
    graphicsView->scale(zoomfactor, zoomfactor);
    @
    For movement of map(like google map with left/right/up/down buttons) I am using below function.
    @graphicsView->centerOn()@

    As soon as user clicks left ,right or up,down button I am moving center of graphics view accordingly by using centerOn() function.

    Is this a correct way of implementing map movemnt? Or plase let me know if there is any better way.

    I want to create effect like google map but it is not giving feel that way. Please reply if anybody know about this.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mkuettler
      wrote on last edited by
      #2

      What is the problem with this solution? It's very hard to help you without knowing this.
      The functions you use do provide one correct way of implementing zooming and moving.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        MyQT
        wrote on last edited by
        #3

        Thanks for the reply,
        The problem is intially map movement to left and right works fine.

        after zooming if I try to move map left or right it doesn't move proper horizontally.

        Below code is used for Zooming
        @
        center = graphicsView->mapToScene(graphicsView->rect().center());
        graphicsView->centerOn(center.rx(),center.ry());

        float zoomfactor;
        if(val == 0)
        {
            zoomfactor = 1.0f;
        }
        else
        {
            zoomfactor = 1.0f + (val * 0.05f);
        }
        

        @

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mlong
          wrote on last edited by
          #4

          Please use @ tags around your code when posting snippets. I have added them above.

          Software Engineer
          My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mkuettler
            wrote on last edited by
            #5

            How does it not "move proper horizontally"? What happens when you click the move button?

            I must admit that I don't quite understand the code. To me it seems that your 12 lines are equivalent to

            @
            float zoomfactor = 1 + val*0.05f;
            @

            The first two lines seem to center the graphicsView on the point that already is its center. Then you calculate the zoomfactor, but in the code you wrote you didn't use it yet. And, if I understand you correctly, zooming works, so I would assume the problem is in the code for moving?

            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