Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOLVED] Problems capturing QGraphicsView in QImage
Hi all, I'm new! Hooray!
I am trying to capture a QGraphicsView widget as part of my testing process. In my test case for the overridden QGraphicsView I add some mock scene data and render to a QImage. However only part of the image is captured. I am pretty new to Qt so I think I must be doing something wrong although I have been looking online for days.
Here's my code:
_mockMapModel = new QGraphicsScene( -100.0, -100.0, 100.0, 100.0 );
_mapView = new MapView(_parent);
QGraphicsEllipseItem *item = new QGraphicsEllipseItem(0,0, 100, 100);
QGraphicsEllipseItem *item2 = new QGraphicsEllipseItem(0, 0, 50, 50);
_mapView->setRenderHints( QPainter::Antialiasing );
_mapView->setSceneRect( 0.0, 0.0, 100.0, 100.0 );
QImage image(_mapView->sceneRect().size().toSize(), QImage::Format_ARGB32);
The image is saved but looks like this:
I have ellipses but the image is cut off below perhaps 50 pixels.
Can anyone explain why? Its like the elipses havent finished rendering
Sorry I should explain that MapView is inheriting QGraphicsView, with no extra functionality or overridden functions (yet).
It turns out the line
@ _mapView = new MapView(_parent);
was clipping the view. By setting the parent to NULL in my test cases, I got the whole view saved in the QImage.