Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QOpenGLWidget and transparency

QOpenGLWidget and transparency

Scheduled Pinned Locked Moved General and Desktop
qt5.5qopenglwidgettransparency
3 Posts 2 Posters 3.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Flassie
    wrote on 31 Aug 2015, 11:27 last edited by
    #1

    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
    {
    public:
        OpenGLWidget(QWidget *parent = 0, const QColor color = QColor(255, 175, 75))
            : QOpenGLWidget(parent)
        {
            QSurfaceFormat format;
            format.setVersion(4, 3);
            format.setRedBufferSize(8);
            format.setGreenBufferSize(8);
            format.setBlueBufferSize(8);
            format.setAlphaBufferSize(8);
            format.setSamples(8);
            setFormat(format);
            this->create();
            m_color = color;
        }
    
    protected:
        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);
    
        }
    
    private:
        QColor m_color;
    };
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
    
        OpenGLWidget w;
        w.show();
        w.setMinimumSize(800, 600);
    
        OpenGLWidget w2(&w, QColor(125, 125, 125, 1));
        w2.setAttribute(Qt::WA_TranslucentBackground);
        w2.setGeometry(w.width()/2 - 40, w.height()/2 - 40, 80, 80);
        w2.show();
    
        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

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Flassie
      wrote on 1 Sept 2015, 20:25 last edited by
      #2

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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DavidArmand
        wrote on 24 Nov 2015, 09:18 last edited by
        #3

        Hi,

        It is a limitation.

        http://doc.qt.io/qt-5/qopenglwidget.html

        "Limitations
        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.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved