PDA

View Full Version : Zooming scene



maverick_pol
2nd August 2007, 12:28
Hi guys,

I am using the QGraphicsScene/View classes in my app. I have a moving rectangle that can be resized and using this rectangle I can choose which part of the scene should be zoomed in? Do you have an idea how to zoom in just a small rectangle from the scene.
QGraphicsView::scale etc, zooms the whole scene. But I need to zoom only the rectangle.
Any ideas?

Thank you.

Maverick

marcel
2nd August 2007, 12:35
Something like a magnifying glass?

I don't think you can do this using only the Graphics View API.
There is no way of zooming only in a part of the scene.

Maybe you can achieve something with QGraphicsScene::render. You know, maybe you can render that area to a pixmap and display that in a rectangle?

Another, more complicated solution( that, however, I am sure it will work ) is to create another graphics view for the very same scene.
This graphics view should be the size of your magnifying rectangle. Also, it should be floating, i.e. not contained in any layout, it will just follow the mouse.Then you can scale the contents of this view as much as you want, since it won't affect the other view.

Regards

Bitto
2nd August 2007, 13:36
On the contrary, it's very possible. I've done this myself as a simple research toy, but can't find the example right now. The magnifying glass is a QGraphicsItem that renders the contents of the scene underneath in paint() using QGraphicsScene::render(), but makes sure to hide itself before and show itself after, to avoid the magnifier itself from being "magnified" into itself.

marcel
2nd August 2007, 13:42
On the contrary, it's very possible. I've done this myself as a simple research toy, but can't find the example right now. The magnifying glass is a QGraphicsItem that renders the contents of the scene underneath in paint() using QGraphicsScene::render(), but makes sure to hide itself before and show itself after, to avoid the magnifier itself from being "magnified" into itself.

But isn't there any quality loss at higher zoom factors, considering we hold the result in a pixmap?

Regards

Gopala Krishna
2nd August 2007, 13:43
I have an idea (though not revolutionary)
Create one more view with same scene and the dimension same as that of required rectangle. Turn off the scrollbars and other unnecessary things.
Here comes the complicated part.
Now obtain the sceneRect that the rectangle(or probably the view itself) covers on the background view. Using this scale the new view using proper calculations and do position it properly using centerOn() or someting similar.

Gopala Krishna
2nd August 2007, 13:59
Actually this is nice question. We can request our "Mr. GraphicsView" (http://aseigo.blogspot.com/2007/08/in-oslo.html) - Andreas to provide this functionality in the upcoming qt versions.

spud
2nd August 2007, 14:38
I might be missing something here, but isn't it as simple as calling


fitInView(selection, Qt::KeepAspectRatio);

selection being the rectangle in scene coords.

marcel
2nd August 2007, 14:39
I might be missing something here, but isn't it as simple as calling


fitInView(selection, Qt::KeepAspectRatio);
selection being the rectangle in scene coords.

Yes, but this only if you implement the magnifying glass as a separate view for the scene.

Regards

Gopala Krishna
2nd August 2007, 14:44
I might be missing something here, but isn't it as simple as calling


fitInView(selection, Qt::KeepAspectRatio);

selection being the rectangle in scene coords.

Yes you are right. I missed this simple thing :)
In that case i guess my idea will work.

maverick_pol
2nd August 2007, 16:10
Hi guys,

Thank you very much for interest and help. I suppose that fitInView(QRectF) will do what I need, but will also consider others ideas.


Thank you.

Maverick

marcel
2nd August 2007, 16:10
In that case i guess my idea will work.

:) Take a look at post #2.

Regards

Gopala Krishna
2nd August 2007, 17:34
:) Take a look at post #2.

Regards

Right. Guess it should be "our" idea or rather our independent ideas. Sorry , i failed to read yours while "skimming" :) This was unintentional :)

marcel
2nd August 2007, 17:37
:)
No problem. I know you didn't see it.
Anyway, at first I didn't think it would work either.


Regards