Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Transparent QWebView over Phonon VideoWidget

    General and Desktop
    3
    8
    6242
    Loading More Posts
    • 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.
    • V
      vsorokin last edited by

      Hello everyone.
      I need put QWebView (ok, any QWidget) with transparent background over Phonon VideoWidget,

      I doing it so:
      @
      m_video = new Phonon::VideoWidget;
      .....
      QWebView *view = new QWebView(mVideo);
      view->setHtml("<div style="color:#FFFFFF;font-size:36px;">Hello Qt!</div>");

      QPalette palette = view->page()->palette();
      palette.setBrush(QPalette::Base, Qt::transparent);
      view->setPalette(palette);
      
      view->setAttribute(Qt::WA_OpaquePaintEvent, false);
      
      m_video->show();
      m_video->resize(640, 480);
      
      view->setFixedSize(m_video->width(), m_video->height());
      

      @

      But I'm not see video under white text, I just see white text on black rectangle.
      Of course, without overlay widget I see video normally.

      Any suggestions?

      --
      Vasiliy

      1 Reply Last reply Reply Quote 0
      • V
        vsorokin last edited by

        I found workaround for this issue:

        This is subclass of Phonon::VideoWidget with overrided events methods.

        @class OverlayedVideoWidget : public Phonon::VideoWidget
        {
        public:
        OverlayedVideoWidget(QWidget *parent = 0) :
        Phonon::VideoWidget(parent),
        m_overlayWidget(0)
        {
        }

        void setOverlayWidget(QWidget *widget)
        {
            m_overlayWidget = widget;
        }
        

        protected:
        void moveEvent(QMoveEvent *event)
        {
        if (m_overlayWidget)
        m_overlayWidget->move(event->pos());
        }

        void resizeEvent(QResizeEvent *event)
        {
            if (m_overlayWidget)
                m_overlayWidget->resize(event->size());
        }
        
        void hideEvent(QHideEvent *)
        {
            if (m_overlayWidget)
                m_overlayWidget->hide();
        }
        
        void showEvent(QShowEvent *)
        {
            if (m_overlayWidget)
                m_overlayWidget->show();
        }
        
        void closeEvent(QCloseEvent *)
        {
            if (m_overlayWidget)
                m_overlayWidget->close();
        }
        

        private:
        QWidget *m_overlayWidget;
        };@

        Usage example:
        @m_video = new OverlayedVideoWidget;

        QWebView *view = new QWebView();
        view->setHtml("<div style="color:#FFFFFF;font-size:36px;">Hello Qt!</div>");
        QPalette palette = view->page()->palette();
        palette.setBrush(QPalette::Base, Qt::transparent);

        view->setPalette(palette);
        view->page()->setPalette(palette);
        view->setAttribute(Qt::WA_OpaquePaintEvent, false);
        view->setAttribute(Qt::WA_TranslucentBackground, true);
        view->setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint);

        m_video->setOverlayWidget(view);
        m_video->show();
        m_video->resize(640, 480);@

        Main idea of this workaround is set to overlayed widget ToolTip window flag and connect move, resize, etc events of both objects.

        --
        Vasiliy

        1 Reply Last reply Reply Quote 0
        • H
          hornuda last edited by

          Hello Vass,

          I really like your solution, this is very smart! I would like to use it, but i have a QGLWidget instead of a QWebView. Is it possible to mark the QGLWidget as ToolTip and only have the OpenGL Objects on top and not the black background from the QGLWidget?

          btw I use Qt4.6

          1 Reply Last reply Reply Quote 0
          • V
            vsorokin last edited by

            I guess it should work with QGLWidget too, because QGLWidget is subclass of QWidget, so technically it's possible and not difficult.

            --
            Vasiliy

            1 Reply Last reply Reply Quote 0
            • H
              hornuda last edited by

              Hm seems that it does not work as easy as I thougt, would you give it a try ?

              1 Reply Last reply Reply Quote 0
              • H
                hornuda last edited by

                So, to answer my own question -> yes it is really easy. Just define Qt::WA_TranslucentBackground to true for your QGLWidget, show it as Tooltip and you will have a nice opengl overlay for your phonon video. Import to enable your composite manager, e.g. Compiz for Linux.

                1 Reply Last reply Reply Quote 0
                • H
                  hornuda last edited by

                  Hello once again,

                  the solution works, but do you think there would be probably a better and cleaner solution ? (referring to http://stackoverflow.com/questions/4473709/play-a-video-with-custom-overlay-graphics/13120078#13120078)

                  1 Reply Last reply Reply Quote 0
                  • V
                    Vaido last edited by

                    bq. the solution works, but do you think there would be probably a better and cleaner solution ? (referring to http://stackoverflow.com/questions/4473709/play-a-video-with-custom-overlay-graphics/13120078#13120078)

                    I am not sure if this solution is better or cleaner but it worked for me. Here is a complete code example, which finally worked after one day of trying...

                    http://www.qtcentre.org/archive/index.php/t-39496.html

                    Good Luck!

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post