Transparency with QOpenGLWidget

  • I have made a widget which inherits from QOpenGLWidget. In the paint event, I call the following code:

    QColor black70 = Qt::black;
    QBrush brush(painter.brush());
    QPen pen(painter.pen());
    QRectF myBox(QPointF(0, -100), QPointF(60, 100));

    In this code, I specifically set the opacity to 30%.

    This widget is drawn on top of another widget. I have found that during the first paint, the opacity renders correctly, but on subsequent paints, the box turns darker and darker until it is finally completely black (no transparency).

    How should I handle this? I don't have the problem when using QWidget instead of QOpenGLWidget.

  • Lifetime Qt Champion


    The questions would rather be:

    • Why use a QGLWidget if doing normal painting ?
    • Why use QGLWidget at all ? QOpenGLWidget is recommended for new development
    • What version of Qt are you using ?
    • What OS are you running ?

  • Sorry, I mispoke in the first post. I am using QOpenGLWidget. I have modified the post appropriately.

    I am targeting an embedded system with limited processor resources, so I was hoping to off-load all of the graphics work to the graphics accelerator. My understanding from this article and this example is that QWidget uses a software rasterizer while QOpenGLWidget uses hardware acceleration.

    This was last tested on Qt 5.10 on Windows 10. I have not tested this aspect on the embedded platform yet. The embedded platform is running Linux 4.14.

Log in to reply