How to overlay transparent areas on a video widget
Unsolved
General and Desktop
-
I want to overlay a transparent areas on a video widget, here is the layout.
Here is what i want:
But i find i cant do it unless use those layout:
Is there any method to achieve my goal with sibling layouts?
-
@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();; }
-