Overlay widget for Phonon VideoWidget: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
If you need put any widget over VideoWidget with transparent background, you | [[Category:HowTo]]<br />[[Category:Snippets]] | ||
If you need put any widget over VideoWidget with transparent background, you can't do it so: | |||
<code><br /> m_video = new Phonon::VideoWidget;<br /> …..<br /> QWebView *view = new QWebView(mVideo);<br /> view->setHtml("<div style=quot;color:#FFFFFF;font-size:36px;quot;>Hello Qt!</div&gt;"); | |||
QPalette palette = view->page()<s>>palette();<br /> palette.setBrush(QPalette::Base, Qt::transparent);<br /> view</s>>setPalette(palette); | |||
view->setAttribute(Qt::WA_OpaquePaintEvent, false); | |||
m_video->show();<br /> m_video->resize(640, 480); | |||
view->setFixedSize(m_video->width(), m_video->height());<br /></code> | |||
You got black background for your widget, It happens because phonon backend might use ''XRender'' for video rendering. | You got black background for your widget, It happens because phonon backend might use ''XRender'' for video rendering. | ||
Line 7: | Line 19: | ||
This is subclass of ''Phonon::VideoWidget'' with overrided events methods. | This is subclass of ''Phonon::VideoWidget'' with overrided events methods. | ||
<code>class OverlayedVideoWidget : public Phonon::VideoWidget<br />{<br />public:<br /> OverlayedVideoWidget(QWidget *parent = 0) :<br /> Phonon::VideoWidget(parent),<br /> m_overlayWidget(0)<br /> {<br /> } | |||
void setOverlayWidget(QWidget *widget)<br /> {<br /> m_overlayWidget = widget;<br /> } | |||
protected:<br /> void moveEvent(QMoveEvent *event)<br /> {<br /> if (m_overlayWidget)<br /> m_overlayWidget->move(event->pos());<br /> } | |||
void resizeEvent(QResizeEvent '''event)<br /> {<br /> if (m_overlayWidget)<br /> m_overlayWidget->resize(event->size());<br /> } | |||
<br /> void hideEvent(QHideEvent''')<br /> {<br /> if (m_overlayWidget)<br /> m_overlayWidget->hide();<br /> } | |||
void showEvent(QShowEvent ''')<br /> {<br /> if (m_overlayWidget)<br /> m_overlayWidget->show();<br /> } | |||
<br /> void closeEvent(QCloseEvent''')<br /> {<br /> if (m_overlayWidget)<br /> m_overlayWidget->close();<br /> } | |||
private:<br /> QWidget *m_overlayWidget;<br />};</code> | |||
Usage example:<br /><code>m_video = new OverlayedVideoWidget; | |||
=== | QWebView *view = new QWebView();<br />view->setHtml("<div style=quot;color:#FFFFFF;font-size:36px;quot;>Hello Qt!</div&gt;");<br />QPalette palette = view->page()<s>>palette();<br />palette.setBrush(QPalette::Base, Qt::transparent); | ||
<br />view</s>>setPalette(palette);<br />view->page()<s>>setPalette(palette);<br />view</s>>setAttribute(Qt::WA_OpaquePaintEvent, false);<br />view->setAttribute(Qt::WA_TranslucentBackground, true);<br />view->setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint); | |||
m_video->setOverlayWidget(view);<br />m_video->show();<br />m_video->resize(640, 480);</code> | |||
Revision as of 10:57, 24 February 2015
If you need put any widget over VideoWidget with transparent background, you can't do it so:
<br /> m_video = new Phonon::VideoWidget;<br /> …..<br /> QWebView *view = new QWebView(mVideo);<br /> view->setHtml("<div style=quot;color:#FFFFFF;font-size:36px;quot;>Hello Qt!</div&gt;");
QPalette palette = view->page()<s>>palette();<br /> palette.setBrush(QPalette::Base, Qt::transparent);<br /> view</s>>setPalette(palette);
view->setAttribute(Qt::WA_OpaquePaintEvent, false);
m_video->show();<br /> m_video->resize(640, 480);
view->setFixedSize(m_video->width(), m_video->height());<br />
You got black background for your widget, It happens because phonon backend might use XRender for video rendering.
Bellow example of workaround, which can help you:
This is subclass of Phonon::VideoWidget with overrided events methods.
class OverlayedVideoWidget : public Phonon::VideoWidget<br />{<br />public:<br /> OverlayedVideoWidget(QWidget *parent = 0) :<br /> Phonon::VideoWidget(parent),<br /> m_overlayWidget(0)<br /> {<br /> }
void setOverlayWidget(QWidget *widget)<br /> {<br /> m_overlayWidget = widget;<br /> }
protected:<br /> void moveEvent(QMoveEvent *event)<br /> {<br /> if (m_overlayWidget)<br /> m_overlayWidget->move(event->pos());<br /> }
void resizeEvent(QResizeEvent '''event)<br /> {<br /> if (m_overlayWidget)<br /> m_overlayWidget->resize(event->size());<br /> }
<br /> void hideEvent(QHideEvent''')<br /> {<br /> if (m_overlayWidget)<br /> m_overlayWidget->hide();<br /> }
void showEvent(QShowEvent ''')<br /> {<br /> if (m_overlayWidget)<br /> m_overlayWidget->show();<br /> }
<br /> void closeEvent(QCloseEvent''')<br /> {<br /> if (m_overlayWidget)<br /> m_overlayWidget->close();<br /> }
private:<br /> QWidget *m_overlayWidget;<br />};
Usage example:
m_video = new OverlayedVideoWidget;
QWebView *view = new QWebView();<br />view->setHtml("<div style=quot;color:#FFFFFF;font-size:36px;quot;>Hello Qt!</div&gt;");<br />QPalette palette = view->page()<s>>palette();<br />palette.setBrush(QPalette::Base, Qt::transparent);
<br />view</s>>setPalette(palette);<br />view->page()<s>>setPalette(palette);<br />view</s>>setAttribute(Qt::WA_OpaquePaintEvent, false);<br />view->setAttribute(Qt::WA_TranslucentBackground, true);<br />view->setWindowFlags(Qt::ToolTip | Qt::FramelessWindowHint);
m_video->setOverlayWidget(view);<br />m_video->show();<br />m_video->resize(640, 480);