PDA

View Full Version : how to zoom out item in View/Scene



nileshsince1980
24th December 2007, 06:03
Hi,

I have GraphicsView/Scene, having multiplpe items in it.
I want to zoom in the view but as the same time I dont want to zoom in the items in scene.
Only background shoud zoom in not the items inside it.
How to I achieve this. ??

Thanks,
Nilesh

wysota
24th December 2007, 09:59
A strange requirement :) You can try setting QGraphicsItem::ItemIgnoresTransformations on your items. Or you can reimplement drawBackground() for your view.

nileshsince1980
26th December 2007, 04:52
Thanks for solution,
I have tried QGraphicsItem::ItemIgnoresTransformations, but If I zoom view with items (say in some ratio) and then I set QGraphicsItem::ItemIgnoresTransformations flag for all items, then all item's shape gets changed to original shape.
e.g. If initial view's zoom scale = 1.0
1st zoom in, scale = scale * 1.2
2nd zoom in, scale = scale * 1.2
and then I set flag QGraphicsItem::ItemIgnoresTransformations fro all items then
items shape gets changed to when scale was 1.
I dont want this behaviour, whatever the last zoom size shoud maintinan same for next zoom in.
How I coud get the item's painter's scale because I have checked and found that in paint(..) fucntion painter's martix gets changed, I want painter's martix before I could set up QGraphicsItem::ItemIgnoresTransformations flag.
Which evet gets fired for this flag. ?????
How could I use the drawBackground() to achieve this ??

wysota
26th December 2007, 10:37
and then I set QGraphicsItem::ItemIgnoresTransformations flag for all items, then all item's shape gets changed to original shape.
Set the flag right after creating each item.


I dont want this behaviour, whatever the last zoom size shoud maintinan same for next zoom in.
You said you wanted your background to scale and items to remain the same. Isn't it what you got?


How could I use the drawBackground() to achieve this ??

I'm not sure what you want to achieve, so it's hard for me to propose a solution. If you tried to explain what effect you want to obtain, maybe it'd be easier to find a solution.

nileshsince1980
26th December 2007, 12:11
Let me explain again,
I want to switch on/off feature of freezing item zoom.
So whenever I switch on( ItemIgnoresTransformations is true), and the do (zoom in/out) operations, items should not get zoom in/out accordingly.

e.g. Consider following sequence of operations,
1. Initial view's scale = 1.00
QGraphicsItem's painter scale = 1.00
2. Operation = zoom in view
View's scale = 1.0 * 1.2 = 1.2
GraphicsItem's painter scale = 1.20
3. Operation = zoom in view
View's scale = 1.2 * 1.2 = 1.44
GraphicsItem's painter scale = 1.44
4. Operation = Freez item zoom
View's scale = 1.44 but
GraphicsItem's painter scale = 1.00
5. Operation = zoom in
View's scale = 1.44 * 1.2 = 1.73
GraphicsItem's painter scale = 1.00

So at step 4, GraphicsItem's painter scale = 1.00, which I don’t want, whatever is last
GraphicsItem's painter scale should remain as it is for next subsequent operations.
In this case, step 4 & 5 should have become like,
4. Operation = Freez item zoom
View's scale = 1.44 but
GraphicsItem's painter scale = 1.44
5. Operation = zoom in
View's scale = 1.44 * 1.2 = 1.73
GraphicsItem's painter scale = 1.44

wysota
26th December 2007, 13:34
I don't think this is easily achievable and I admit I don't know what you need it for. What you can try is to create a QGraphicsItemGroup when you want to "freeze" items, put all items into the group and make the group item ignore transformations. I don't know if you'll obtain the effect you seek for but based on your explanation, it should be something like that.

nileshsince1980
28th December 2007, 08:05
In my case GraphicsItem's painter scale means



GraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
{
QMatrix m;
m = painter->matrix();
// draw rect
painter->drawRect(rect);
}


I have checked the matrix (m = painter->matrix()) which is gets reset when I set flag ItemIgnoresTransformations.
You can check painter's scale changes by creating simple applcation with GraphicsView/Scene and adding some rects/ellipse in it. and then zooming for 3 times and then setting ItemIgnoresTransformations flag for all items. You can observe matrix (m) changes.

Can you tell me which events gets send to GraphicsItem when view's matrix get changed.
other than paint(...) ??

wysota
28th December 2007, 10:24
But why do you want to paint the background using the graphics view architecture if you immediately disable all it gives you.

As for the event, take a look at QGraphicsItem::itemChange().