Using QStackedLayout for overlaying an OpenGL widget



  • Hi,

    I am currently tring to use a QStackedLayout to add overlay widgets on top of an OpenGL widget (not a QOpenGLWidget, but a regular QWidget in which I draw with an external graphics engine thanks to the window handle). I have set the QStackedLayout stacking mode to "StackAll" in order to see the whole widget stack.
    But I can't get to see the OpenGL widget under my overlay widget. It always appears like if the OpenGL widget was "discarded", just like if there was nothing drawn in it but just fully transparent.

    Is there any hint with using a QStackedWidget to achieve what I want to do? Or maybe is it not the correct solution?

    Thanks.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Can you share a sample code where you setup that ?



  • Here is how I try to use it.

    QWidget* mainWidget;
    QStackedLayout *stackedLayout = new QStackedLayout;
    mainWidget->setLayout(stackedLayout);
    
    QWidget* ogreWidget = new QWidget();
    ... // code to create OGRE context
    stackedLayout->addWidget(ogreWidget);
    
    QWidget* overlayWidget;
    QVBoxLayout* vBoxLayout = new QVBoxLayout();
    vBoxLayout->setContentsMargins(0, 0, 0, 0);
    overlayWidget->addLayout(hBoxLayout);
    ... // Some child widgets created and added to the overlayWidget
    stackedLayout->addWidget(overlayWidget);
    
    stackedLayout->setStackingMode(QStackedLayout::StackAll):
    
    

    The widget named ogreWidget is a QWidget in which I render an OpenGL scene with OGRE3D. I get the winId of the widget and I send it to OGRE, and then OGRE owns its OpenGL context and manages it.
    With this code I can correctly see the overlay widgets, but the OGRE widget underneath seems to be discarded, I see only the widget which is under the mainWidget (but Debug mode showed me that the rendering is made, the widget seems to be updated correctly). If I deactivate the overlay stack, the OGRE widget is correctly showing.


  • Lifetime Qt Champion

    What about positioning your overlay widget by hand rather that through QStackedLayout ?



  • Well I have found out that using a QGraphicsScene to host my overlaying widgets seems to be working and it is easy to manipulate them, so I'll go with the QGraphicsView / QGraphicsScene solution.
    Thanks


  • Lifetime Qt Champion

    Good idea !


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.