Custom-context-QGLWidget causes problems
-
Hello!
I have a QGLWidget with a custom QGLContext. I am trying to have regular QT Gui elements (simple QWidgets) drawn on top of it, but somehow I can't manage to do that and I think it should be possible. I tried putting the QWidgets as direct children of the QGLWidget, or to put all widget into a container-widget, but the same problem occurs every time - the normal QWidgets have black background, and their children-widgets appear different than if I'd put the QWidget as a top-level window... You would say, "then why don't you let them be separate windows floating above the QGLWidget?" - The answer is, I want to have some of the GUI to shine through (translucent).Here is the code of the paintEvent() function of the QGLWidget:
The part of QGLWidget which creates the custom format in the constructor is here:
@
// setFormat(fmt) is marked as deprecated so we use this other method
QGLContext* glctx = new QGLContext(context()->format(), this);
QGLFormat fmt = context()->format();// double buffer
fmt.setDoubleBuffer( true );// color buffer
fmt.setRedBufferSize( 8 );
fmt.setGreenBufferSize( 8 );
fmt.setBlueBufferSize( 8 );
// setAlpha == true makes the create() function alway fail
// even if the returned format has the requested alpha channel
fmt.setAlphaBufferSize( 8 );
fmt.setAlpha( true );fmt.setAccumBufferSize( 0);
fmt.setAccum( false );// multisampling
fmt.setSamples( 8 );
fmt.setSampleBuffers( true );// depth buffer
fmt.setDepthBufferSize( 24 );
fmt.setDepth( true );// stencil buffer
fmt.setStencilBufferSize( 8 );
fmt.setStencil( true );glctx->setFormat(fmt);
// this function returns false when we request an alpha buffer
// even if the created context seem to have the alpha buffer
/*bool ok = */glctx->create(shareContext);
setContext(glctx);
@@
//And here the paintEvent function of the QGLWidget:
makeCurrent();QPainter painter(this);
painter.beginNativePainting();glEnable(GL_MULTISAMPLE);
//paints some native GL stuff
dispatchRunEvent();painter.endNativePainting();
swapBuffers();
@@
//the constructor of the normal QWidget
setStyleSheet("background-color:blue;");
@When the QWidget has parent=0, it appears blue as intended...
I would appreciate any help or advice, I feel like I tried everything already...
-
So no one has an idea about where the problem is? I also tried using a QGraphicsSCene and a QGraphicsView with a viewport set to my QGLWidget, but it fails with a GLContext=null error (probably because in the QGLWidget I create a custom context...).