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. Displaying a QWidget with Transparent Background over a QMediaPlayer

Displaying a QWidget with Transparent Background over a QMediaPlayer

Scheduled Pinned Locked Moved General and Desktop
qmultimediatransparencyqwidget
6 Posts 2 Posters 7.0k Views
  • 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.
  • T Offline
    T Offline
    tmason202
    wrote on 12 Apr 2015, 22:15 last edited by
    #1

    Hello,

    I am trying to get a transparent QWidget to display over a QMediaPlayer object.

    The goal is to have a semi-transparent QWidget that displays playback, volume, etc. controls over a QMediaPlayer widget.

    As it stands now the control displays but there is no transparency over the QMediaPlayer object. What do I need to do to make that happen?

    Thank you.

    Here is the following code for the QWidget I am trying to make semi-transparent:

    class QTSemiTransparentWidget : public QWidget {
    
    	Q_OBJECT
    
    public:
    
    	explicit QTSemiTransparentWidget(QWidget* parent = NULL);
    	~QTSemiTransparentWidget();
    
    public slots:
    
    signals:
    
    protected:
    
    private:
    
    private slots :
    
    	virtual void prepareUI();
    
    };
    

    And here is the implementation:

    #include "QTSemiTransparentWidget.h"
    
    QTSemiTransparentWidget::QTSemiTransparentWidget(QWidget* parent) : QWidget(parent) {
    
    	prepareUI();
    
    }
    
    QTSemiTransparentWidget::~QTSemiTransparentWidget() {
    
    
    
    }
    
    void QTSemiTransparentWidget::prepareUI() {
    
    	this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
    	this->setAttribute(Qt::WA_NoSystemBackground);
    	this->setAttribute(Qt::WA_TranslucentBackground, true);
    	this->setAttribute(Qt::WA_PaintOnScreen);
    	this->setAttribute(Qt::WA_TransparentForMouseEvents);
    	
    	this->setWindowOpacity(0.5);
    
    }
    
    R 1 Reply Last reply 12 Apr 2015, 23:25
    0
    • T tmason202
      12 Apr 2015, 22:15

      Hello,

      I am trying to get a transparent QWidget to display over a QMediaPlayer object.

      The goal is to have a semi-transparent QWidget that displays playback, volume, etc. controls over a QMediaPlayer widget.

      As it stands now the control displays but there is no transparency over the QMediaPlayer object. What do I need to do to make that happen?

      Thank you.

      Here is the following code for the QWidget I am trying to make semi-transparent:

      class QTSemiTransparentWidget : public QWidget {
      
      	Q_OBJECT
      
      public:
      
      	explicit QTSemiTransparentWidget(QWidget* parent = NULL);
      	~QTSemiTransparentWidget();
      
      public slots:
      
      signals:
      
      protected:
      
      private:
      
      private slots :
      
      	virtual void prepareUI();
      
      };
      

      And here is the implementation:

      #include "QTSemiTransparentWidget.h"
      
      QTSemiTransparentWidget::QTSemiTransparentWidget(QWidget* parent) : QWidget(parent) {
      
      	prepareUI();
      
      }
      
      QTSemiTransparentWidget::~QTSemiTransparentWidget() {
      
      
      
      }
      
      void QTSemiTransparentWidget::prepareUI() {
      
      	this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
      	this->setAttribute(Qt::WA_NoSystemBackground);
      	this->setAttribute(Qt::WA_TranslucentBackground, true);
      	this->setAttribute(Qt::WA_PaintOnScreen);
      	this->setAttribute(Qt::WA_TransparentForMouseEvents);
      	
      	this->setWindowOpacity(0.5);
      
      }
      
      R Offline
      R Offline
      Ruslan F.
      wrote on 12 Apr 2015, 23:25 last edited by
      #2

      @tmason202 watch at QGraphicsOpacityEffect or reimplement paintEvent and use QPainter::setOpacity

      T 1 Reply Last reply 13 Apr 2015, 00:45
      0
      • T Offline
        T Offline
        tmason202
        wrote on 13 Apr 2015, 00:29 last edited by
        #3

        Hello!

        This is what I tried:

        this->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
        	
        	transparencyEffect = new QGraphicsOpacityEffect(this);
        	transparencyEffect->setOpacity(0.5);
        
        	this->setGraphicsEffect(transparencyEffect);
        

        In the "prepareUI" function. But the transparency is still not applied to the class object.

        What am I doing wrong?

        Thank you.

        1 Reply Last reply
        0
        • R Ruslan F.
          12 Apr 2015, 23:25

          @tmason202 watch at QGraphicsOpacityEffect or reimplement paintEvent and use QPainter::setOpacity

          T Offline
          T Offline
          tmason202
          wrote on 13 Apr 2015, 00:45 last edited by
          #4

          @Ruslan-F.

          I also tried this:

          void QTSemiTransparentWidget::paintEvent(QPaintEvent* event) {
          
          	QPainter mainPainter(this);
          	mainPainter.setOpacity(0.5);
          
          }
          

          But still no transparency.

          R 1 Reply Last reply 15 Apr 2015, 09:16
          0
          • T Offline
            T Offline
            tmason202
            wrote on 13 Apr 2015, 10:02 last edited by
            #5

            Hello,

            So, I figured this out; what I ended up doing was creating a QGraphicsView and then have the QMediaPlayer display it's output to a QGraphicsVideoItem which was then attached to the scene.

            I ended up getting transparency as I needed but it cost me a little bit of performance. I will be researching what I need to do to bump up performance.

            Thank you for the help.

            1 Reply Last reply
            0
            • T tmason202
              13 Apr 2015, 00:45

              @Ruslan-F.

              I also tried this:

              void QTSemiTransparentWidget::paintEvent(QPaintEvent* event) {
              
              	QPainter mainPainter(this);
              	mainPainter.setOpacity(0.5);
              
              }
              

              But still no transparency.

              R Offline
              R Offline
              Ruslan F.
              wrote on 15 Apr 2015, 09:16 last edited by Ruslan F.
              #6

              @tmason202 , try this one

              void QTSemiTransparentWidget::paintEvent(QPaintEvent* event) {
              
                  QPainter painter(this);
                  painter.setOpacity(0.5);
                  QStyleOption opt;
                  opt.initFrom(this);
                  QStyle* pStyle =  QApplication::style();
                  pStyle->drawPrimitive(QStyle::PE_Widget, &opt, &painter, this);
              
              }
              

              at least you should draw something in paint event not to just set an opacity.

              1 Reply Last reply
              0

              6/6

              15 Apr 2015, 09:16

              • Login

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