PDA

View Full Version : QGraphicsItem and it's position at QGraphicsView



silverado
15th February 2012, 16:59
I've got a problem with QGraphicsView and the stuff.

What I wanna do, is to load an Image, display it and give user the ability to move it around and zoom in/zoom out. Here is what are my assumptions:

1. The image is moved freely until the edge of QGraphicsItem meets the edge of QGraphicsView. I just dont want the Item (if it is smaller than View) to exceed the viewing area. If it is larger (wider or higher) I don't want to move it more than it needs to (i.e. if the upper edge of item exceeds the viewport, cuz its higher than viewport and the bottom edge of Item meets the bottom edge of viewport I want it to stop.) The hard thing is to get Items position at viewport. Howto get it?

2. Zooming out Is possible until the longer edge of rectangle Item fits the viewport. Zooming in is possible until some extends (defined by me). Do i guess right it (zooming in/out) could be easily done by QTransform?

More or less i wanna do Interface like at Google Maps instead map i wanna view finite Pixmap, and i wanna get the place at image where the user clicked mouse (thats why think QGraphicsItem is so neet in this situation).

I guess both issues could be easily done if i would knew Items position at viewport, not at scene. Is there any possibility to determine it?

Any other solutions that would make ui like that come to life are also welcome.

Spitfire
20th February 2012, 15:28
Why you need to know position of the item in the viewport?
Anyway, you can use mapFromScene (http://developer.qt.nokia.com/doc/qt-4.8/qgraphicsview.html#mapFromScene-6)/mapToScene (http://developer.qt.nokia.com/doc/qt-4.8/qgraphicsview.html#mapToScene-2) if you need.