Qt: How to correct grabbing invisible/hidden widgets?

1.5k Views Asked by At

I need to grab a widget in order to save it as an image file. I use the following code:

QPixmap img = this->webView->grab();
img.save("image.PNG);

This doesn't work though when the application has been minimized or the grabbed widget is a child of QStackedWidget or QTabWidget.

Please, help me solve this problem.

1

There are 1 best solutions below

3
On

Try this:

QPushButton button("123");
button.resize(100, 100);
button.hide();    

QPixmap p(button.size());
button.render(&p);
p.save("1.png");