PDA

View Full Version : QgraphicsView/Scene to PNG image



nileshsince1980
6th May 2010, 06:42
Hi All,

My application consists of QGraphicsView/Scene nad I have added QGraphicsItems of different shapes line rectangle, circle etc. etc.
I want to convernt whatever is in QGraphicsScene to image file (e.g. scene.png).
Can you tell how to do this ???
I have tried 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");


But above code only creates png file with background image (which I draw in
QGraphicsScene:drawBackground(QPainter * painter, QRectF const & /*clip*/) { } method using QPainterPath class.
The items which I added doesnt get added in png file.
Can you anybody tell me what I am missing ??

Thanks in advance.
Nilesh

aamer4yu
6th May 2010, 08:10
At what cordinates are your items ? are they within the 1024x768 rect in the scene ?

nileshsince1980
6th May 2010, 08:28
I have set scene rect's as (0, 0, 550, 700).
I want entire scene should get saved as a image.

aamer4yu
6th May 2010, 09:18
(0, 0, 550, 700). seems ok.
try changing image format from ARGB32premultiplied to some other and check if it works.