Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] How to play a video on a translucent QWidget?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hdeldar
    wrote on last edited by
    #1

    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);
    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&#40;"C:/1.wmv"&#41;&#41;;
    
    mediaPlayer.play(&#41;;
    
    w->show(&#41;;
    return app.exec(&#41;;
    

    }
    @

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

    1 Reply Last reply
    0
    • H Offline
      H Offline
      hdeldar
      wrote on last edited by
      #2

      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
      painter.setCompositionMode(QPainter::RasterOp_SourceAndDestination);
      @
      to change the composition mode.

      L 1 Reply Last reply
      0
      • H hdeldar

        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
        painter.setCompositionMode(QPainter::RasterOp_SourceAndDestination);
        @
        to change the composition mode.

        L Offline
        L Offline
        liyingzai
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved