As is widely known that, to make a QWidget
/QOpenGLWidget
translucent/transparent, one only needs to:
widget->setAttribute(Qt::WA_TranslucentBackground)
However, since QWindow
/QOpenGLWindow
is not a widget and doesn't have setAttribute
, I don't know how to do the same for a QOpenGLWindow
. I guess this is theoretically possible since QWidget
is backed by a QWindow
according to Qt's source code.
I searched on Google but there's not much information about the transparency of QWindow
I found out that this will happen in
QOpenGLWindow
byQSurfaceFormat
andsetAlphaBufferSize(8);
Look at this example:
in mainwindow.h
in mainwindow.cpp
and finally in main.cpp
I
w.setFormat(format);
which means thatQOpenGLWindow
orMainWindow
notQOpenGLContext
.This will be the Result: