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; black70.setAlphaF(0.3); QBrush brush(painter.brush()); brush.setColor(black70); brush.setStyle(Qt::SolidPattern); painter.setBrush(brush); QPen pen(painter.pen()); pen.setColor(Qt::white); pen.setWidthF(0.5); painter.setPen(pen); QRectF myBox(QPointF(0, -100), QPointF(60, 100)); painter.drawRect(myBox);
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.
-
Hi,
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.