PDA

View Full Version : QGraphicsView/Scene to png image



nileshsince1980
21st May 2010, 11:58
Hi All
My application consists of QGraphicsView/Scene with some shapes like rectange items.
I have option to save entire scene to an image file using following code


QGraphicsScene scene;

scene->addItem(rectItem);
scene->addItem(rectItem);
//.....

QImage img(1024,768,QImage::Format_ARGB32_Premultiplied);
QPainter p(&img);
scene.render(&p);
p.end();
img.save("scene.png");


Image is gets saved propertly. but when I tried to zoom in GraphicsView by setting matrix. and then save the image, tthe image which I get is of initial scale level.
e..g Initial scale is 1 after zoom in say GraphicsView's scale becomes 2
but image (scene.png) is created with initial scale of 1.

Can any body tell what I missing ??
Thanks in advance.

Nilesh

high_flyer
21st May 2010, 12:25
You are saving an image with a fixed size always:

QImage img(1024,768,QImage::Format_ARGB32_Premultiplied);


You have to calculate the correct image size for the zoomed scene.

[EDIT]:
Oh, I see now what you mean.
You want a fixed size image, and only the zoomed part of the scene in it.
You have to draw the visible scene rect in to the image then.

nileshsince1980
21st May 2010, 13:40
I want entire zoomed scene should get saved as an image. But even the scene items are zoomed in, and then saving image I am getting image of initial zoom scale.

What is the solution for this ??

high_flyer
21st May 2010, 14:27
The scene object is not a visible object.
It only holds information about the proportions of its consents (very simply put).

If you want the whole scene in the QImage, and you want it scaled, then resize the QImage.