My application contains a QWidget->QGridLayout with multiple QGLWidgets dynamically laid out. I am trying to capture a QImage of all the QGLWidgets in the layout to save. I have tried:
QImage image
( mainWidget
->rect
().
size(),
QImage::Format_RGB32 );
mainWidget->render( &painter );
image.save( filename );
QImage image( mainWidget->rect().size(), QImage::Format_RGB32 );
QPainter painter( &image );
mainWidget->render( &painter );
image.save( filename );
To copy to clipboard, switch view to plain text mode
and
image.save( filename );
QPixmap image = QPixmap::grabWidget( mainWidget );
image.save( filename );
To copy to clipboard, switch view to plain text mode
both result in the "skeleton" of the widget being saved, but the individual QGLWidgets are not rendered/visible. Using QGLWidget::grabFrameBuffer works fine, but just on a single QGLWidget, not on all at once.
The QPixmap::grabWidget gives a warning message that says
QGLContext::chooseContext() : SetPixelFormat failed: The pixel format is invalid.
Is there anyway of doing this or do I need to code together the stiching of the QImages together (slow!).
Thanks!
My application contains a QWidget->QGridLayout with multiple QGLWidgets dynamically laid out. I am trying to capture a QImage of all the QGLWidgets in the layout to save. I have tried:
QImage image
( mainWidget
->rect
().
size(),
QImage::Format_RGB32 );
mainWidget->render( &painter );
image.save( filename );
QImage image( mainWidget->rect().size(), QImage::Format_RGB32 );
QPainter painter( &image );
mainWidget->render( &painter );
image.save( filename );
To copy to clipboard, switch view to plain text mode
and
image.save( filename );
QPixmap image = QPixmap::grabWidget( mainWidget );
image.save( filename );
To copy to clipboard, switch view to plain text mode
both result in the "skeleton" of the widget being saved, but the individual QGLWidgets are not rendered/visible. Using QGLWidget::grabFrameBuffer works fine, but just on a single QGLWidget, not on all at once.
The QPixmap::grabWidget gives a warning message that says
QGLContext::chooseContext() : SetPixelFormat failed: The pixel format is invalid.
Is there anyway of doing this or do I need to code together the stiching of the QImages together (slow!).
Thanks!
Added after 13 minutes:
I guess I just needed a little more trial and error time, I just needed to create a QGLContext for my QGLWidget in inititializeGL:
context->create();
context->makeCurrent();
QGLContext *context = new QGLContext( myFormat );
context->create();
context->makeCurrent();
To copy to clipboard, switch view to plain text mode
Then the QPixmap code worked beautifully!
image.save( filename );
QPixmap image = QPixmap::grabWidget( mainWidget );
image.save( filename );
To copy to clipboard, switch view to plain text mode
Hope this helps someone else out in the future!
Bookmarks