0

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.

scopchanov
  • 7,966
  • 10
  • 40
  • 68
ioann sys
  • 1
  • 2

1 Answers1

0

Try this:

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

QPixmap p(button.size());
button.render(&p);
p.save("1.png");
samdavydov
  • 564
  • 3
  • 22
  • I try that, before questing, but it don't work :( At now, i use next workaround: # Create new Widget – ioann sys Jun 29 '17 at 12:34
  • 1
    Can you post some more code? This tiny example works fine. Looks like smth wrong may be in another place. – samdavydov Jun 29 '17 at 12:40
  • Thank for your answer. I try it before questing, but not working. Now i use next workaround: 1. Create widget with attributes Qt::WA_DontShowOnScreen | Qt::WA_ShowWithoutActivating | Qt::WA_AlwaysOnTop; 2. Move webView widget to new widget; 3. grabbing from new widget; 4. moving webView to back in QTabWidget Maybe Qt have special flags or attributes like as Qt::WA_DrawWhenMinimized? – ioann sys Jun 29 '17 at 12:44