[SOLVED] Saving a QImage from multiple QGLWidgets
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:
Code:
QImage image
( mainWidget
->rect
().
size(),
QImage::Format_RGB32 );
mainWidget->render( &painter );
image.save( filename );
and
Code:
image.save( filename );
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
Quote:
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:
Code:
QImage image
( mainWidget
->rect
().
size(),
QImage::Format_RGB32 );
mainWidget->render( &painter );
image.save( filename );
and
Code:
image.save( filename );
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
Quote:
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:
Code:
context->create();
context->makeCurrent();
Then the QPixmap code worked beautifully!
Code:
image.save( filename );
Hope this helps someone else out in the future!
Re: [SOLVED] Saving a QImage from multiple QGLWidgets
Re: [SOLVED] Saving a QImage from multiple QGLWidgets
Except I dont want the entire contents of the window. There are other controlling widgets outside the desired area that I do not want captured. It is simpler to capture the widget I need than calculating where my widget resides in the window. Plus I do not have to worry about other windows inadvertently being on top (such as the Save dialog).
Quote:
Originally Posted by
high_flyer
Re: [SOLVED] Saving a QImage from multiple QGLWidgets
Can't you layout your stuff in one GLWidget and grab that one? Maybe even use a graphics scene and a graphic layout and put your individual sub glwidgets as normal widgets or qgraphicsitems into it.
Joh
Re: Saving a QImage from multiple QGLWidgets
There are other things that were not pertinent to this post, such as: the OpenGL widgets are part of a custom Plotting library, which to keep generic (hence the library), each object only contains one "plot". Most instances, only a single plot is needed, but this is a different circumstance, which needed multiple plots per window. Adding multiple plots to a single QGLWidget would be a major change to this library that I do not have the time/money for ATM. Thanks though