20083

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?

Edit:

#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(); }

Answer1:

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 this case i use a custom video widget and in paintEvent after createing QPainter painter(this); add

painter.setCompositionMode(QPainter::RasterOp_SourceAndNotDestination); or painter.setCompositionMode(QPainter::RasterOp_SourceAndDestination);

to change the composition mode.

Answer2:

I've implemented VideoWidget some time ago. The only thing you shall change is your video path and set FramelessWindowHint flag.

You can find source here.

Recommend

  • Why is QSlider not updating it's position immediately in its UI?
  • Besides memory management, what's a QObject's parent used for?
  • Can't import QtMultimedia in PyQt 5 on Windows
  • Python kernel dies for second run of PyQt5 GUI
  • QT Start program as regular user
  • Pass Arbitrary Sized 2 Dimension Array
  • What is lua_len() alternative in Lua 5.1?
  • std::system Exception when instantiating a singleton object
  • Call a macro with parameters : Python win32com API
  • Get the App path without the app name at the end of the app
  • Getting short path in python
  • How to read piped content in C?
  • How solve “Qt: Untested Windows version 10.0 detected!”
  • C: Incompatible pointer type initializing
  • how to adjust image in a panel in Java swing?
  • Java Scanner input dilemma. Automatically inputs without allowing user to type
  • Is calc() supported in html email?
  • req.body is undefined - nodejs
  • Problems to linebreak with an int in JLabel
  • How reduce the height of an mschart by breaking up the y-axis
  • AES padding and writing the ciphertext to a disk file
  • output of program is not same as passed argument
  • MySQL WHERE-condition in procedure ignored
  • Symfony2: How to get request parameter
  • Convert array of 8 bytes to signed long in C++
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Akka Routing: Reply's send to router ends up as dead letters
  • Is there a mandatory requirement to switch app.yaml?
  • Linker errors when using intrinsic function via function pointer
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • LevelDB C iterator
  • unknown Exception android
  • Checking variable from a different class in C#
  • Sorting a 2D array using the second column C++
  • Observable and ngFor in Angular 2
  • How to Embed XSL into XML
  • UserPrincipal.Current returns apppool on IIS
  • Conditional In-Line CSS for IE and Others?
  • java string with new operator and a literal