QQuickwidget grab image outside window area

420 Views Asked by At

This is a sequel to another question here in which I was not precise while describing my goal.

As mentioned in the linked question, I wish to save a QML which is embedded in a QQuickWidget and it is larger than the window size. The QQuickWindow grabWindow() method captures only the window area and hence I tried the following code after I visually displayed it:

QQuickWidget* content..
content->setSource(QUrl("qml:/main.qml"));
QPixmap *pm = content->grab(QRect(QPoint(0,0),QSize(-1,-1));
pm->save("someFilename.png", 0, 100);

So, it is definitely not the issue of saving image after rendering. The used QML code is just a plain Rectangle. The proposed solutions in the previous question only grabs content falling within the window.

Any suggestions? Thanks! :)

Addendum:

I have tried the following but didn't work:

QImage paintdev(largeWidth, largeHeight, QImage:Format_RBG32);
content->render(paintdev, QPoint(0,0), QRegion(QRect(0,0,largeWidth, largeHeight), QWidget::DrawChildren);
paintdev.save(fileName, 0, 100);

This should by logic solve the issue of window size since there is no window. Any comments?

2

There are 2 best solutions below

1
On

If your QML content is larger than the window size, the part that is out of screen is not drawn. Hence, there is no way to capture something out of screen, unless you use 2 monitors and extend view. This last approach would work.

0
On

Ok, so I solved it by manually shifting the QML by the window height and saving all the images from the window captures and collate it to form the original image.

Not too much work though, but I am still mystified by the QWidget render() method which did not work.

Thanks for all the replies!