Important: Please read the Qt Code of Conduct -

QOpenGLWidget and transparency

  • Hi. I have problems with QOpenGLWidget and transparency. Here is my code:

    #include <QApplication>
    #include <QOpenGLWidget>
    #include <QOpenGLFunctions>
    #include <QOpenGLFunctions_4_3_Core>
    #include <QDebug>
    class OpenGLWidget : public QOpenGLWidget
        OpenGLWidget(QWidget *parent = 0, const QColor color = QColor(255, 175, 75))
            : QOpenGLWidget(parent)
            QSurfaceFormat format;
            format.setVersion(4, 3);
            m_color = color;
        void initializeGL() {
            QOpenGLFunctions_4_3_Core *f = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_4_3_Core>();
            qDebug() << m_color;
            f->glClearColor(m_color.redF(), m_color.greenF(), m_color.blueF(), m_color.alphaF());
        void paintGL() {
            auto f = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_4_3_Core>();
            f->glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        void resizeGL(int w, int h) {
            auto f = QOpenGLContext::currentContext()->versionFunctions<QOpenGLFunctions_4_3_Core>();
            f->glViewport(0, 0, w, h);
        QColor m_color;
    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        OpenGLWidget w;;
        w.setMinimumSize(800, 600);
        OpenGLWidget w2(&w, QColor(125, 125, 125, 1));
        w2.setGeometry(w.width()/2 - 40, w.height()/2 - 40, 80, 80);;
        return a.exec();

    When I'm creating second widget (w2) I'm settings it's alpha to 1 (doesn't matter if I will set it to 0, or 100, or 255) but it looks like as it has 255. How can I solve this problem?

    I'm using Qt 5.5, mingw32 and windows 10

  • I don't believe that noone had the same problem and didn't solved it

  • Hi,

    It is a limitation.

    Putting other widgets underneath and making the QOpenGLWidget transparent will not lead to the expected results: The widgets underneath will not be visible. This is because in practice the QOpenGLWidget is drawn before all other regular, non-OpenGL widgets, and so see-through type of solutions are not feasible. Other type of layouts, like having widgets on top of the QOpenGLWidget, will function as expected."

    You have to use Qt::WA_AlwaysStackOnTop to do this.