I have a QGraphicsView and on this view I place several subclassed QGraphicsItems which implement their own paint method. Now I want to render the graphicsview/scene to an image and save this to disk. I use the following method to render the scene to an image:

Qt Code:
  1. QPainter *pngPainter = new QPainter();
  2. QImage *image = new QImage(QSize(width,height), QImage::Format_ARGB32_Premultiplied);
  3.  
  4. pngPainter->begin(image);
  5. pngPainter->setRenderHint(QPainter::Antialiasing);
  6. _ui->graphicsView->scene()->render(pngPainter);
  7. pngPainter->end();
  8. image->save(fileName);
  9.  
  10. delete pngPainter;
  11. delete image;
To copy to clipboard, switch view to plain text mode 

This works perfectly when I use QPainter commands in the paint procedure of the QGraphicsItems, like so (block is a QRectF):

Qt Code:
  1. void CNodeGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  2. {
  3. // color setup
  4. painter->setPen(Qt::red);
  5. painter->setBrush(Qt::red);
  6.  
  7. painter->drawRect(block);
  8. }
To copy to clipboard, switch view to plain text mode 

However, If (for performance reasons and in order to use shaders) I use native opengl commands, like so:

Qt Code:
  1. void CNodeGraphicsItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  2. {
  3. painter->beginNativePainting();
  4. glBegin(GL_QUADS);
  5. setGLColor(Qt::red); // Own function to set glColor3f;
  6. glTexCoord2f (0.0, 0.0);glVertex2d(block.left(),block.top());
  7. glTexCoord2f (1.0, 0.0);glVertex2d(block.right(),block.top());
  8. glTexCoord2f (1.0, 1.0);glVertex2d(block.right(),block.bottom());
  9. glTexCoord2f (0.0, 1.0);glVertex2d(block.left(),block.bottom());
  10. glEnd();
  11. painter->endNativePainting();
  12. }
To copy to clipboard, switch view to plain text mode 

It no longer works and the output is an entire black image. The rendering on the QGraphicsView gives the expected result though (a red rectangle). Any ideas on how to solve this / make it work with native opengl commands?

I know I can grab the framebuffer:
Qt Code:
  1. QImage img = ((QGLWidget*)_ui->graphicsView->viewport())->grabFrameBuffer(true);
  2. img.save(fileName, "PNG", 100);
To copy to clipboard, switch view to plain text mode 

This works, however the output image is only the size of the graphicsView, I want to be able
to output high-res images.