How to play a video on a translucent QWidget?



  • #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);
    w->setMinimumSize(300,200);
    
    QVideoWidget *videoWidget = new QVideoWidget;
    QBoxLayout *controlLayout = new QHBoxLayout;
    controlLayout->setMargin(0);
    controlLayout->addWidget(videoWidget);
    w->setLayout(controlLayout);
    
    QMediaPlayer mediaPlayer;
    mediaPlayer.setVideoOutput(videoWidget);
    mediaPlayer.setMedia(QUrl::fromLocalFile("C:/1.wmv"));
    videoWidget->show();
    mediaPlayer.play();
    
    w->show();
    return app.exec();
    

    }

    when two line w->setWindowFlags(Qt :: Window | Qt::FramelessWindowHint ); w->setAttribute(Qt::WA_TranslucentBackground, true); remove the movie show correctly.
    somebody tell ,in this case i use a custom video widget and in paintEvent after createing QPainter painter(this); add
    painter.setCompositionMode(QPainter::RasterOp_SourceAndNotDestination); but i use, it is No effect! Someone met?Someone met ?Someone solution?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.