Cannot display QVideoWidget when TranslucentBackground is on and cannot disable TranslucentBackground ?
-
I am on Windows 10 using Qt5 in Mingw.
I have a Hierarchy ofQMainWindow > QWidget (=centralWidget) > QVBoxLayout > Content
.The
Content
depends on which file the user opens. If it is an image file,Content
is a subclass ofQLabel
and shows the image with any transparent parts completely see-through, i.e. any background windows or the desktop can be seen. I have this working and usesetAttribute(Qt::WA_TranslucentBackground);
in my
QMainWindow
subclass to achieve this.If the user instead opens a video file, I want
Content
to be a different widget, which is a subclass ofQVideoWidget
with aQMediaPlayer
member that plays the video. The playback itself also works. I do not care to show the videos transparent like the images. Videos can be fully opaque.However, my problem is that with
WA_TranslucentBackground
active, theQVideoWidget
does not show up at all, it is completely transparent, and I cannot see anything except the taskbar entry of my application.. even if the video is not transparent. If I do not setWA_TranslucentBackground
, then the video shows, but the images are (of course) no longer shown transparent.I tried many different things to try and resolve the issue, but nothing works:
- before
show()
/hide()
callsetAttribute(Qt::WA_TranslucentBackground, false);
- this does not seem to do anything - do not call
setAttribute(Qt::WA_TranslucentBackground);
forQMainWindow
, but forContent
instead, only in the image case - this does not work: the images are not shown transparent - instead of
hide()
/show()
, useremoveWidget(...
/addWidget(...
on theQVBoxLayout
- again this does nothing, both of the first two points show the same behavior - instead of
hide()
/show()
,delete
andnew
the differentContent
s - still does nothing, same behavior as above
At this point I am stuck. Why does Qt show the videos completely transparent when
WA_TranslucentBackground
is active? Is there any way to fix this? Alternatively, how do I dynamically enable / disableWA_TranslucentBackground
properly, assetAttribute(..., false);
seems to do nothing? - before