我想使用QVideoWidget或QGraphicsVideoItem在具有Qt :: FramelessWindowHint标志和Qt :: WA_TranslucentBackground attirbute的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();
}
答案 0 :(得分:3)
我解决了这个问题。当我们设置WA_TranslucentBackground标志和FramelessWindowHint属性时,QVideoWidget的QPainter进入QPainter :: CompositionMode_DestinationOver模式,它会导致屏幕上无显示或阴影。在这种情况下,我使用自定义视频小部件,并在创建QPainter画家后使用paintEvent(这);添加
painter.setCompositionMode(QPainter::RasterOp_SourceAndNotDestination); or
painter.setCompositionMode(QPainter::RasterOp_SourceAndDestination);
更改构图模式。
答案 1 :(得分:1)
我前段时间实施过VideoWidget。您唯一要改变的是视频路径并设置FramelessWindowHint标志。
您可以找到来源here。