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. Transparent QWebView over Phonon VideoWidget

Transparent QWebView over Phonon VideoWidget

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 6.8k 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.
  • V Offline
    V Offline
    vsorokin
    wrote on last edited by
    #1

    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
    0
    • V Offline
      V Offline
      vsorokin
      wrote on last edited by
      #2

      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
      0
      • H Offline
        H Offline
        hornuda
        wrote on last edited by
        #3

        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
        0
        • V Offline
          V Offline
          vsorokin
          wrote on last edited by
          #4

          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
          0
          • H Offline
            H Offline
            hornuda
            wrote on last edited by
            #5

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

            1 Reply Last reply
            0
            • H Offline
              H Offline
              hornuda
              wrote on last edited by
              #6

              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
              0
              • H Offline
                H Offline
                hornuda
                wrote on last edited by
                #7

                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
                0
                • V Offline
                  V Offline
                  Vaido
                  wrote on last edited by
                  #8

                  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
                  0

                  • Login

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