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
Contentdepends on which file the user opens. If it is an image file,Contentis a subclass ofQLabeland 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
QMainWindowsubclass to achieve this.If the user instead opens a video file, I want
Contentto be a different widget, which is a subclass ofQVideoWidgetwith aQMediaPlayermember 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_TranslucentBackgroundactive, theQVideoWidgetdoes 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 forContentinstead, 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(),deleteandnewthe differentContents - still does nothing, same behavior as above
At this point I am stuck. Why does Qt show the videos completely transparent when
WA_TranslucentBackgroundis active? Is there any way to fix this? Alternatively, how do I dynamically enable / disableWA_TranslucentBackgroundproperly, assetAttribute(..., false);seems to do nothing? - before