Cannot display QVideoWidget when TranslucentBackground is on and cannot disable TranslucentBackground ?

  • I am on Windows 10 using Qt5 in Mingw.
    I have a Hierarchy of QMainWindow > QWidget (=centralWidget) > QVBoxLayout > Content.

    The Content depends on which file the user opens. If it is an image file, Content is a subclass of QLabel 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 use


    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 of QVideoWidget with a QMediaPlayer 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, the QVideoWidget 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 set WA_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() call setAttribute(Qt::WA_TranslucentBackground, false); - this does not seem to do anything
    • do not call setAttribute(Qt::WA_TranslucentBackground); for QMainWindow, but for Content instead, only in the image case - this does not work: the images are not shown transparent
    • instead of hide() / show(), use removeWidget(... / addWidget(... on the QVBoxLayout - again this does nothing, both of the first two points show the same behavior
    • instead of hide() / show(), delete and new the different Content 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 / disable WA_TranslucentBackground properly, as setAttribute(..., false); seems to do nothing?

Log in to reply