May 8, 2012

Vass Vass
Hobby Entomologist
738 posts

Transparent QWebView over Phonon VideoWidget

 

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

I doing it so:

  1.     m_video = new Phonon::VideoWidget;
  2.     .....
  3.     QWebView *view = new QWebView(mVideo);
  4.     view->setHtml("<div style=\"color:#FFFFFF;font-size:36px;\">Hello Qt!</div>");
  5.  
  6.     QPalette palette = view->page()->palette();
  7.     palette.setBrush(QPalette::Base, Qt::transparent);
  8.     view->setPalette(palette);
  9.  
  10.     view->setAttribute(Qt::WA_OpaquePaintEvent, false);
  11.  
  12.     m_video->show();
  13.     m_video->resize(640, 480);
  14.  
  15.     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?

 Signature 


Vasiliy

7 replies

May 12, 2012

Vass Vass
Hobby Entomologist
738 posts

I found workaround for this issue:

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

  1. class OverlayedVideoWidget : public Phonon::VideoWidget
  2. {
  3. public:
  4.     OverlayedVideoWidget(QWidget *parent = 0) :
  5.         Phonon::VideoWidget(parent),
  6.         m_overlayWidget(0)
  7.     {
  8.     }
  9.  
  10.     void setOverlayWidget(QWidget *widget)
  11.     {
  12.         m_overlayWidget = widget;
  13.     }
  14.  
  15. protected:
  16.     void moveEvent(QMoveEvent *event)
  17.     {
  18.         if (m_overlayWidget)
  19.             m_overlayWidget->move(event->pos());
  20.     }
  21.  
  22.     void resizeEvent(QResizeEvent *event)
  23.     {
  24.         if (m_overlayWidget)
  25.             m_overlayWidget->resize(event->size());
  26.     }
  27.  
  28.     void hideEvent(QHideEvent *)
  29.     {
  30.         if (m_overlayWidget)
  31.             m_overlayWidget->hide();
  32.     }
  33.  
  34.     void showEvent(QShowEvent *)
  35.     {
  36.         if (m_overlayWidget)
  37.             m_overlayWidget->show();
  38.     }
  39.  
  40.     void closeEvent(QCloseEvent *)
  41.     {
  42.         if (m_overlayWidget)
  43.             m_overlayWidget->close();
  44.     }
  45.  
  46. private:
  47.     QWidget *m_overlayWidget;
  48. };

Usage example:

  1. m_video = new OverlayedVideoWidget;
  2.  
  3. QWebView *view = new QWebView();
  4. view->setHtml("<div style=\"color:#FFFFFF;font-size:36px;\">Hello Qt!</div>");
  5. QPalette palette = view->page()->palette();
  6. palette.setBrush(QPalette::Base, Qt::transparent);
  7.  
  8. view->setPalette(palette);
  9. view->page()->setPalette(palette);
  10. view->setAttribute(Qt::WA_OpaquePaintEvent, false);
  11. view->setAttribute(Qt::WA_TranslucentBackground, true);
  12. view->setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint);
  13.  
  14. m_video->setOverlayWidget(view);
  15. m_video->show();
  16. 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.

 Signature 


Vasiliy

October 25, 2012

hornuda hornuda
Lab Rat
5 posts

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

October 25, 2012

Vass Vass
Hobby Entomologist
738 posts

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

 Signature 


Vasiliy

October 25, 2012

hornuda hornuda
Lab Rat
5 posts

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

October 25, 2012

hornuda hornuda
Lab Rat
5 posts

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.

November 7, 2012

hornuda hornuda
Lab Rat
5 posts

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)

December 6, 2012

Vaido Vaido
Lab Rat
11 posts

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!

 
  ‹‹ How to use ActiveX controls in Qt 4.7.4?      How to config ActiveX controls and COM object in qt 4.7.4 ››

You must log in to post a reply. Not a member yet? Register here!