Transparent QWidget over a QGLWidget



  • I am trying to have a transparent QWidget over a QGLWidget something like below:

    QWidget *transparentWidget = new QWidget;
    transparentWidget->setFixedSize(1440, 720);
    transparentWidget->setAttribute(Qt::WA_TranslucentBackground);
    
    QGLWidget *glWidget  = new QGLWidget;
    transparentWidget->setParent(glWidget);
    transparentWidget->setGeometry(10, 50, 500, 500);
    
    transparentWidget->show();
    glWidget->show();
    

    But I am not getting the desired result. transparentWidget is being added at the specified geometry, however it is not transparent.

    How can I fix this??

    Any leads would be appreciated....



  • Hi,
    Combine the setAttribute(Qt::WA_TranslucentBackground) with setWindowOpacity


  • Moderators

    Also, if you are on Qt 5.4 or newer, I suggest replacing QGLWidget with QOpenGLWidget. QOpenGLWidget resolves numerous issues with QGLWidget: https://blog.qt.io/blog/2014/09/10/qt-weekly-19-qopenglwidget/


Log in to reply
 

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