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. How to overlay transparent areas on a video widget
Forum Update on Tuesday, May 27th 2025

How to overlay transparent areas on a video widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 368 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.
  • Q Offline
    Q Offline
    Quiccz
    wrote on last edited by
    #1

    base on https://forum.qt.io/topic/151408/calling-the-hide-function-for-a-widget-only-hides-the-visual-representation-not-the-widget-itself?_=1698373724873

    I want to overlay a transparent areas on a video widget, here is the layout.
    f88f424c-50d0-467e-986e-cc7776c46320-image.png

    Here is what i want:
    3e290193-693f-4202-b87f-d5f82ff2bb96-image.png

    But i find i cant do it unless use those layout:
    df611679-da0d-4d46-8e9d-31ffaa646846-image.png d5c57602-6242-4b8c-bf38-993deccff41e-image.png

    Is there any method to achieve my goal with sibling layouts?

    jsulmJ 1 Reply Last reply
    0
    • Q Quiccz

      base on https://forum.qt.io/topic/151408/calling-the-hide-function-for-a-widget-only-hides-the-visual-representation-not-the-widget-itself?_=1698373724873

      I want to overlay a transparent areas on a video widget, here is the layout.
      f88f424c-50d0-467e-986e-cc7776c46320-image.png

      Here is what i want:
      3e290193-693f-4202-b87f-d5f82ff2bb96-image.png

      But i find i cant do it unless use those layout:
      df611679-da0d-4d46-8e9d-31ffaa646846-image.png d5c57602-6242-4b8c-bf38-993deccff41e-image.png

      Is there any method to achieve my goal with sibling layouts?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Quiccz You should post your relevant code.
      "But i find i cant do it unless use those layout" - in what way it doesn't work?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Q 1 Reply Last reply
      1
      • jsulmJ jsulm

        @Quiccz You should post your relevant code.
        "But i find i cant do it unless use those layout" - in what way it doesn't work?

        Q Offline
        Q Offline
        Quiccz
        wrote on last edited by Quiccz
        #3

        @jsulm not work when they have same parent

        #pragma once
        #include <QWidget>
        #include <QQuickWidget>
        #include "VideoWidget.h"
        #include "OpenGLWidget.h"
        class MyWidget: public QWidget
        {
        public:
            MyWidget(QWidget *parent);
            void SetSubWidget();
        };
        
        #include "Mywidget.h"
        MyWidget::MyWidget(QWidget* parent)
        : QWidget(parent)
        {
            this->setGeometry(0,0, 1920, 1080);
            this->setWindowFlags(Qt::FramelessWindowHint);
            QPalette palette;
            palette.setColor(QPalette::Window, Qt::GlobalColor::black);
            this->setAutoFillBackground(true);
            this->setPalette(palette);
            this->show();
        }
        
        void MyWidget::SetSubWidget()
        {
            VideoWidget* videoWidget = new VideoWidget(this);
            videoWidget->setGeometry(0, 0, 512, 384);
            QPalette palette1;
            palette1.setColor(QPalette::Window, Qt::GlobalColor::red);
            videoWidget->setAutoFillBackground(true);
            videoWidget->setPalette(palette1);
            videoWidget->show();
        
        
            // not work
            QWidget* transparentWidget1 = new QWidget(this);
            transparentWidget1->setGeometry(0, 0, 100, 100);
            transparentWidget1->show();
            
            // work
            QWidget* transparentWidget2 = new QWidget(nullptr);
            transparentWidget2->setAttribute(Qt::WA_TranslucentBackground, true);
            transparentWidget2->setWindowFlags(Qt::FramelessWindowHint);
            transparentWidget2->setGeometry(100, 100, 100, 100);
            transparentWidget2->show();
            
            // work
            QWidget* transparentWidget3 = new QWidget(videoWidget);
            transparentWidget3->setGeometry(200, 200, 100, 100);
            transparentWidget3->show();
        }
        
        #pragma once
        #include <QWidget>
        #include <mpv/client.h>
        class VideoWidget : public QWidget
        {
        Q_OBJECT
        public:
        	VideoWidget(QWidget* parent);
        private:
        	mpv_handle* mpv;
        };
        
        #include "VideoWidget.h"
        
        VideoWidget::VideoWidget(QWidget* parent)
        	:QWidget(parent)
        {
            mpv = mpv_create();
            if (!mpv)
            {
                qDebug() << "could not create mpv context";
                throw std::runtime_error("could not create mpv context");
            }
            int64_t  wid = this->winId();
            mpv_set_property(mpv, "wid", MPV_FORMAT_INT64, &wid);
        
            qDebug() << "wid is " << wid;
            mpv_set_property_string(mpv, "hwdec", "auto");
            mpv_set_property_string(mpv, "loop-file", "inf");
            if (mpv_initialize(mpv) < 0)
            {
                qDebug() << "could not initialize mpv context";
                throw std::runtime_error("could not initialize mpv context");
            }
            const char* args[] = { "loadfile", "4k_60.mp4", NULL };
            mpv_command_async(mpv, 0, args);
        }
        
        #include <QWidget>
        #include "Mywidget.h"
        #include <QApplication>
        #include <QTimer>
        
        
        int main(int argc, char *argv[])
        {
            QApplication app(argc, argv);
        
            MyWidget *mywidget = new MyWidget(nullptr);
            QTimer::singleShot(2000, mywidget, [&]() {
                mywidget->SetSubWidget();
                });
            return app.exec();;
        }
        

        abfb2130-c16a-454c-a9a5-fb353fca09b6-image.png

        1 Reply Last reply
        0
        • Q Quiccz referenced this topic on

        • Login

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