Render just a specific area of a QGraphicsScene
-
Hello all, relatively new here, but I came across some cool posts in the past and now I have a very own problem trying to being solved. Hope you could help out here!
So I catch the rubberBandChanged signal and return the values I require to get the underlying part of the QGraphicsScene.
QRect rect, QPointF from, QPointF to)
. With that I should be able to render just the part of the current QGraphicsScene, I selected with the rubberBand:// EditorView is a QGraphicsView void EditorView::imageFromRectRequested(const QRect &_rect, const QPointF &_from, const QPointF &_to) { QImage _img(_rect.size(), QImage::Format_ARGB32); QPainter _p(&_img); this->scene()->render(&_p, _img.rect(), _rect); _img.save("Z:\\Documents\\test.png"); }
It does render a part of the QGraphicsScene, with the correct size, but not with the correct position. Where do I do something wrong, what do I misunderstood about that concept?
Any help appreciated!
Many thanks!
nitroo -
Hi and welcome to devnet,
Did you map the coordinates to the scene at some point ?
-
Hi @SGaist,
thank you for your welcome!
No, currently not. I thought
this->scene()->render()
does the trick on the current scene. Where do I need to map the coordinates I get from the QGraphicsView rubberband in order to get the underlying part of the image? I don't know where to really add the coordinates..~nitroo
-
@nitro0 It seems worth noting that you pass _from and _to to your function, but never use them. Did you intend to? If not, I am confused why they are part of the signature.
I'd guess that rect you are using is just in the "wrong position" and you don't include anything about how exactly it is made, or what is wrong about it.
-
@wrosecrans
I know that I need them. But don‘t know how to apply them on the scene and keep everything thats on that. I thought that the rect itself has the points in it using the render function of the QGraphicsScene is enough.What I do: I set the DragMode of the QGraphicsView to rubberband so the user can select some part pf the scene by simply dragging. The returned rect is now sent to the view to get the underlying image of the scene.