c++ - Rendering a QGraphicsScene to QImage results in objects being placed on a side of QImage -


my qgraphicsscene quite large, , qgraphicsview fit small portion of it.

i print/save qgraphicsscene

outputview::outputview(qwidget *parent)     : qgraphicsview(parent) {...}  void outputview::savetoimage()  {     qimage image(scene()->scenerect().size().tosize(), qimage::format_mono);     image.fill(qt::transparent);     qpainter painter(&image);     render(&painter);     image.save("output.png"); } 

of course experimenting, placing objects in center of viewport...

the saved image contains objects, location of objects on left side of image

input: enter image description here

output: enter image description here (screenshot windows photo viewer)

it seems image created correct size, viewport contents rendered - top left corner of viewport on top left corner of image, leaving rest of image empty.

why happening ? doing wrong ?

update:

trying

fitinview(scene()->scenerect()); 

results in viewport showing entire image, zoomed ... saved image still contains viewport (only tiny)

enter image description here

and answer in additional explanation.

i should have done

scene()->render(&painter); 

i rendering viewport.... not scene


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -