Overlay widget for Phonon VideoWidget: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
(Sub-categorize) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
If you need put any widget over VideoWidget with transparent background, you | {{Cleanup | reason=Auto-imported from ExpressionEngine.}} | ||
[[Category:HowTo]] | |||
[[Category:Snippets::Misc]] | |||
If you need put any widget over VideoWidget with transparent background, you can't do it so: | |||
<code> | |||
m_video = new Phonon::VideoWidget; | |||
….. | |||
QWebView *view = new QWebView(mVideo); | |||
view->setHtml("<div style=quot;color:#FFFFFF;font-size:36px;quot;>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()); | |||
</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 30: | ||
This is subclass of ''Phonon::VideoWidget'' with overrided events methods. | This is subclass of ''Phonon::VideoWidget'' with overrided events methods. | ||
Usage example:< | <code>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; | |||
};</code> | |||
Usage example: | |||
<code>m_video = new OverlayedVideoWidget; | |||
QWebView *view = new QWebView(); | |||
view->setHtml("<div style=quot;color:#FFFFFF;font-size:36px;quot;>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);</code> |
Latest revision as of 12:03, 28 November 2016
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine. Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean. |
If you need put any widget over VideoWidget with transparent background, you can't do it so:
m_video = new Phonon::VideoWidget;
…..
QWebView *view = new QWebView(mVideo);
view->setHtml("<div style=quot;color:#FFFFFF;font-size:36px;quot;>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());
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
{
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=quot;color:#FFFFFF;font-size:36px;quot;>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);