Important: Please read the Qt Code of Conduct -

[solved] How to play a video on a translucent QWidget?

  • I want to play a movie on a QWidget that has Qt::FramelessWindowHint flag and Qt::WA_TranslucentBackground attirbute using QVideoWidget or QGraphicsVideoItem. But the video is not visible. I hear only sound. What is the problem?

    #include "videoplayer.h"

    #include <QtWidgets/QApplication>
    #include "qboxlayout.h"
    #include "qvideowidget.h"

    int main(int argc, char *argv[])
    QApplication app(argc, argv);
    QWidget *w = new QWidget;
    w->setWindowFlags(Qt :: Window | Qt::FramelessWindowHint );
    w->setAttribute(Qt::WA_TranslucentBackground, true);

    QVideoWidget *videoWidget = new QVideoWidget;
    QBoxLayout *controlLayout = new QHBoxLayout;
    QMediaPlayer mediaPlayer;
    return app.exec(&#41;;


    when two line
    w->setWindowFlags(Qt :: Window | Qt::FramelessWindowHint ); w->setAttribute(Qt::WA_TranslucentBackground, true);
    remove the movie show correctly.

  • I solve the problem .when we set the WA_TranslucentBackground flag and FramelessWindowHint attribute the QVideoWidget's QPainter going to QPainter::CompositionMode_DestinationOver mode and it cause to nothing to show or a shadow on the screen . in the case i use a custom video widget and in paintEvent after createing QPainter painter(this); add
    painter.setCompositionMode(QPainter::RasterOp_SourceAndNotDestination); or
    to change the composition mode.

  • @hdeldar I did it in your way, but I did not work Correct.
    Can you show me your demo?

Log in to reply