QGraphicsview & QGraphicsScene movement with Zoomin & Zoom out, How to create map movement like google map?
-
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.
-
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. -
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); }
@
-
Please use @ tags around your code when posting snippets. I have added them above.
-
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?