I have a QGraphicsScene with a few QGraphicsPixmapItems and the QGraphicsProxyWidget added to it. When the screenshot is taken the the QGraphicsProxyWidget doesn't show up in the screenshot.

The code for the screenshot i tried unsuccessfully are the following :-
Qt Code:
  1. QPixmap MainWindow::getScreenShot(){
  2. QPixmap screenshotPixmap = ui->graphicsView->grab();
  3. return screenshotPixmap;
  4. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. QPixmap MainWindow::getScreenShot(){
  2. QImage img(scene->sceneRect().size().toSize(), QImage::Format_ARGB32_Premultiplied);
  3. QPainter painter(&img);
  4. //scene->render(&painter);
  5. ui->graphicsView->render(&painter);
  6. QPixmap tempPixmap;
  7. tempPixmap.convertFromImage(img);
  8. return tempPixmap;
  9. }
To copy to clipboard, switch view to plain text mode 

What other alternative methods can be used to get the screenshot with the QGraphicsProxyWidget also present in it?