<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[PARTIALLY SOLVED] QML &#x2F; ShadersEffectItem &#x2F; Transparency]]></title><description><![CDATA[<p dir="auto">I have several questions around the QML / shaderEffectItem and transparency.<br />
Shall I begin with the first one: I am developping under Windows XP; using the mingw compilation toolchain, and Qt 4.7.4.</p>
<p dir="auto">I just want to first create a QmlApplicationViewer of size 1024*768, with trransparency.</p>
<p dir="auto">Then I want to display a png of size 968*640 (containing transparency parts) inside this QmlApplicationViewer at position 50,50. So I expect to have transparency around the image, and inside the image itself.</p>
<p dir="auto">-&gt;My application gives me the following result: i have the opaque part of the image displayed correctly, but all transparent parts I was expecting, (around the image, and in the image itself) are full of dirty stuff probably coming from a buffer that was not cleared before.</p>
<p dir="auto">Any idea how I could have a clean result?</p>
<p dir="auto">Here is my code:</p>
<p dir="auto">main.cpp<br />
@#include &lt;QtGui/QApplication&gt;<br />
#include &lt;QtOpenGL&gt;<br />
#include "qmlapplicationviewer.h"</p>
<p dir="auto">Q_DECL_EXPORT int main(int argc, char *argv[])<br />
{<br />
#ifdef OPENGL_GRAPHICSSYSTEM<br />
QApplication::setGraphicsSystem("opengl");<br />
#endif</p>
<pre><code>QScopedPointer&lt;QApplication&gt; app(createApplication(argc, argv&amp;#41;);
QScopedPointer&lt;QmlApplicationViewer&gt; viewer(QmlApplicationViewer::create());
</code></pre>
<p dir="auto">#ifndef OPENGL_GRAPHICSSYSTEM<br />
QGLFormat format = QGLFormat::defaultFormat();<br />
format.setSampleBuffers(false);<br />
format.setSwapInterval(1);<br />
QGLWidget* glWidget = new QGLWidget(format);<br />
glWidget-&gt;setAutoFillBackground(false);<br />
viewer-&gt;setViewport(glWidget);<br />
#endif</p>
<pre><code>viewer-&gt;setViewportUpdateMode(QGraphicsView::FullViewportUpdate);

viewer-&gt;setAttribute(Qt::WA_TranslucentBackground);
viewer-&gt;setAttribute(Qt::WA_NoSystemBackground);
viewer-&gt;setStyleSheet("background:transparent;");
viewer-&gt;setWindowFlags(Qt::FramelessWindowHint);
viewer-&gt;setOrientation(QmlApplicationViewer::ScreenOrientationAuto);

viewer-&gt;setMainQmlFile&amp;#40;QLatin1String("qml/maskproject/main.qml"&amp;#41;&amp;#41;;
viewer-&gt;showExpanded();

return app-&gt;exec(&amp;#41;;
</code></pre>
<p dir="auto">}<br />
@</p>
<p dir="auto">main.qml<br />
@<br />
import QtQuick 1.0<br />
import Qt.labs.shaders 1.0</p>
<p dir="auto">Rectangle {<br />
width: 1024<br />
height: 768<br />
color: "transparent"</p>
<p dir="auto">Image {<br />
id:source<br />
x:50<br />
y:50<br />
width:968<br />
height:645<br />
source: "../../../_DSC5401.jpg"<br />
}<br />
}<br />
@</p>
<p dir="auto">Any idea what is wrong here?<br />
Thank you,<br />
Bill</p>
]]></description><link>https://forum.qt.io/topic/12293/partially-solved-qml-shaderseffectitem-transparency</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Apr 2026 19:14:07 GMT</lastBuildDate><atom:link href="https://forum.qt.io/topic/12293.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 16 Dec 2011 14:06:18 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [PARTIALLY SOLVED] QML &#x2F; ShadersEffectItem &#x2F; Transparency on Tue, 20 Dec 2011 09:31:49 GMT]]></title><description><![CDATA[<p dir="auto">I think it's ok ... if "he" isn't clearing it's ok if you do. :)<br />
Performance-vice it shouldn't be a big deal do clear the color-buffer... but maybe someone with more opengl-performance-experience has an opinion?</p>
<p dir="auto">@<br />
glWidget-&gt;setAutoFillBackground(false);<br />
@<br />
I think this is the problem.<br />
You have disabled any background painting on the viewport (which is then overwritten by you via reimplementing the drawBackground of the DeclarativeView).<br />
What he's then doing is painting transparent ... which is then composed with the "background".<br />
If you try a half-transparent red as your Rectangle color, I would guess you would see red garbage :)</p>
<p dir="auto">... the only thing which is strange is that:<br />
@<br />
viewer-&gt;setViewportUpdateMode(QGraphicsView::FullViewportUpdate);<br />
@<br />
should clear the color buffer for every frame ...</p>
]]></description><link>https://forum.qt.io/post/121207</link><guid isPermaLink="true">https://forum.qt.io/post/121207</guid><dc:creator><![CDATA[nicolauz]]></dc:creator><pubDate>Tue, 20 Dec 2011 09:31:49 GMT</pubDate></item><item><title><![CDATA[Reply to [PARTIALLY SOLVED] QML &#x2F; ShadersEffectItem &#x2F; Transparency on Mon, 19 Dec 2011 15:52:56 GMT]]></title><description><![CDATA[<p dir="auto">Finally got something working:<br />
1 - add the workaround in the qmlViewerApplication as follows:<br />
<a class="plugin-mentions-user plugin-mentions-a" href="/user/void">@<bdi>void</bdi></a> QmlApplicationViewer::drawBackground(QPainter* painter, const QRectF&amp;)<br />
{<br />
painter-&gt;beginNativePainting();<br />
glClearDepthf(1.f);<br />
glClearColor(0.f, 0.f, 0.f, 0.f);<br />
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);<br />
painter-&gt;endNativePainting();<br />
}@</p>
<p dir="auto">2- initialise your qmlApplicationViewer as follows:<br />
@#include &lt;QtGui/QApplication&gt;<br />
#include "qmlapplicationviewer.h"<br />
#include &lt;QtOpenGL&gt;</p>
<p dir="auto">int main(int argc, char *argv[])<br />
{</p>
<pre><code>QScopedPointer&lt;QApplication&gt; app(createApplication(argc, argv));
QScopedPointer&lt;QmlApplicationViewer&gt; viewer(QmlApplicationViewer::create());

viewer-&gt;setWindowFlags(Qt::FramelessWindowHint);
viewer-&gt;setAttribute(Qt::WA_NoSystemBackground);
viewer-&gt;setStyleSheet("background: transparent;");
QPalette palette;
palette.setColor(QPalette::Base, Qt::transparent);
viewer-&gt;setPalette(palette);

viewer-&gt;setOrientation(QmlApplicationViewer::ScreenOrientationAuto);
viewer-&gt;setMainQmlFile&amp;#40;QLatin1String("qml/SimpleOpenGLWithTransparency/main.qml"&amp;#41;&amp;#41;;

QGLFormat format = QGLFormat::defaultFormat();
format.setSampleBuffers(false);
format.setSwapInterval(1);
format.setAlpha(true);

QGLWidget *glWidget = new QGLWidget(format);
glWidget-&gt;setAutoFillBackground(false);
viewer-&gt;setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
viewer-&gt;setViewport(glWidget);

viewer-&gt;showExpanded();


return app-&gt;exec&amp;#40;&amp;#41;;
</code></pre>
<p dir="auto">}<br />
@</p>
<p dir="auto">Thank you Mathias for your suggestions, thank you Thomas also, even if your tricks did not work for me.</p>
<p dir="auto">Best of luck for all!<br />
Bill</p>
<p dir="auto">[Edited for code syntax highlighting. -Bradley]</p>
]]></description><link>https://forum.qt.io/post/121115</link><guid isPermaLink="true">https://forum.qt.io/post/121115</guid><dc:creator><![CDATA[billouparis]]></dc:creator><pubDate>Mon, 19 Dec 2011 15:52:56 GMT</pubDate></item><item><title><![CDATA[Reply to [PARTIALLY SOLVED] QML &#x2F; ShadersEffectItem &#x2F; Transparency on Mon, 19 Dec 2011 15:24:45 GMT]]></title><description><![CDATA[<p dir="auto">I tested all solution, apparently none is working for me, neither on PC XP, nor on Target/embedded system Device.</p>
]]></description><link>https://forum.qt.io/post/121109</link><guid isPermaLink="true">https://forum.qt.io/post/121109</guid><dc:creator><![CDATA[billouparis]]></dc:creator><pubDate>Mon, 19 Dec 2011 15:24:45 GMT</pubDate></item><item><title><![CDATA[Reply to [PARTIALLY SOLVED] QML &#x2F; ShadersEffectItem &#x2F; Transparency on Mon, 19 Dec 2011 14:28:07 GMT]]></title><description><![CDATA[<p dir="auto">Another guy from another working with us, told me he found a workaround by modifying the qmlApplicationViewer and replacing/adding the following:</p>
<p dir="auto">"The only way i found to circumvent this issue is to overwrite QGraphicsView::drawBackground() in the QMLApplicationViewer:</p>
<p dir="auto">void QmlApplicationViewer::drawBackground(QPainter* painter, const QRectF&amp;)<br />
{<br />
painter-&gt;beginNativePainting();<br />
glClearDepthf(1.f);<br />
glClearColor(0.f, 0.f, 0.f, 0.f);<br />
glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT);</p>
<p dir="auto">painter-&gt;endNativePainting();<br />
}</p>
<p dir="auto">Maybe there is another way.</p>
<p dir="auto">"</p>
<p dir="auto">Do you know if it's a good solution? or if there is something else I could try without changing the qmlApplicationViewer itself?<br />
Thank you,<br />
Bill</p>
]]></description><link>https://forum.qt.io/post/121101</link><guid isPermaLink="true">https://forum.qt.io/post/121101</guid><dc:creator><![CDATA[billouparis]]></dc:creator><pubDate>Mon, 19 Dec 2011 14:28:07 GMT</pubDate></item><item><title><![CDATA[Reply to [PARTIALLY SOLVED] QML &#x2F; ShadersEffectItem &#x2F; Transparency on Mon, 19 Dec 2011 14:19:22 GMT]]></title><description><![CDATA[<p dir="auto">Hello Thomas, I have tried both solutions, both on PC WindowsXP, and on our Target iMX53 linux/Wayland based, with no success in either case :(<br />
I am still getting dirty data all over the place in the transparent areas...<br />
I am doomed!<br />
Bill</p>
]]></description><link>https://forum.qt.io/post/121102</link><guid isPermaLink="true">https://forum.qt.io/post/121102</guid><dc:creator><![CDATA[billouparis]]></dc:creator><pubDate>Mon, 19 Dec 2011 14:19:22 GMT</pubDate></item><item><title><![CDATA[Reply to [PARTIALLY SOLVED] QML &#x2F; ShadersEffectItem &#x2F; Transparency on Mon, 19 Dec 2011 14:04:14 GMT]]></title><description><![CDATA[<p dir="auto">Hey Thomas, do you think a<br />
format.setAlpha(true);</p>
<p dir="auto">could also improve things?<br />
Bill</p>
]]></description><link>https://forum.qt.io/post/121098</link><guid isPermaLink="true">https://forum.qt.io/post/121098</guid><dc:creator><![CDATA[billouparis]]></dc:creator><pubDate>Mon, 19 Dec 2011 14:04:14 GMT</pubDate></item><item><title><![CDATA[Reply to [PARTIALLY SOLVED] QML &#x2F; ShadersEffectItem &#x2F; Transparency on Mon, 19 Dec 2011 12:56:18 GMT]]></title><description><![CDATA[<p dir="auto">I think all you need to do is setting TranslucentBackground on the viewport(!!!):<br />
glWidget-&gt;setAttribute(Qt::WA_TranslucentBackground);</p>
<p dir="auto">... this should do magic<br />
(before and/or after setViewport ... there is something going on when setting the viewport .. moving this line around in the code can improve things a lot ;) )</p>
<p dir="auto">... if this doesn't help, try to add:<br />
glWidget-&gt;qglClearColor(Qt::transparent);</p>
<p dir="auto">I got no MS-Windows machine here, but it should be ... somewhat similar on linux and window  ;)</p>
]]></description><link>https://forum.qt.io/post/121081</link><guid isPermaLink="true">https://forum.qt.io/post/121081</guid><dc:creator><![CDATA[nicolauz]]></dc:creator><pubDate>Mon, 19 Dec 2011 12:56:18 GMT</pubDate></item><item><title><![CDATA[Reply to [PARTIALLY SOLVED] QML &#x2F; ShadersEffectItem &#x2F; Transparency on Mon, 19 Dec 2011 09:21:26 GMT]]></title><description><![CDATA[<p dir="auto">I think we have such an implementation on our embedded device. I tried this code:<br />
@#include &lt;QtGui/QApplication&gt;<br />
#include "qmlapplicationviewer.h"<br />
#include &lt;QtOpenGL&gt;</p>
<p dir="auto">Q_DECL_EXPORT int main(int argc, char *argv[])<br />
{<br />
#ifdef OPENGL_GRAPHICSSYSTEM<br />
QApplication::setGraphicsSystem("opengl");<br />
#endif</p>
<pre><code>QScopedPointer&lt;QApplication&gt; app(createApplication(argc, argv));
QScopedPointer&lt;QmlApplicationViewer&gt; viewer(QmlApplicationViewer::create());
</code></pre>
<p dir="auto">#ifndef OPENGL_GRAPHICSSYSTEM<br />
QGLFormat format = QGLFormat::defaultFormat();<br />
format.setSampleBuffers(false);<br />
format.setSwapInterval(1);</p>
<pre><code>QGLWidget* glWidget = new QGLWidget(format);
glWidget-&gt;setAutoFillBackground(false);
viewer-&gt;setViewport(glWidget);
</code></pre>
<p dir="auto">#endif</p>
<pre><code>viewer-&gt;setViewportUpdateMode(QGraphicsView::FullViewportUpdate);

// viewer.setAttribute(Qt::WA_OpaquePaintEvent);
//viewer-&gt;setWindowFlags(Qt::FramelessWindowHint|Qt::SplashScreen);
//viewer-&gt;setAttribute(Qt::WA_TranslucentBackground);
viewer-&gt;setAttribute(Qt::WA_NoSystemBackground);
viewer-&gt;setStyleSheet("background: transparent;");
viewer-&gt;setFrameStyle(QFrame::NoFrame);
viewer-&gt;setOrientation(QmlApplicationViewer::ScreenOrientationAuto);

viewer-&gt;setMainQmlFile&amp;#40;QLatin1String("qml/SimpleOpenGLWithTransparency/main.qml"&amp;#41;);
viewer-&gt;showExpanded();

return app-&gt;exec&amp;#40;&amp;#41;;
</code></pre>
<p dir="auto">}</p>
<p dir="auto">@</p>
<p dir="auto">And on our target it displays white color instead of transparent. We have two different hardware framebuffers, my app is running in the FB on top, and i can not see through. If I remove the openGL initialization, I can see through the image without any problem.</p>
<p dir="auto">Do you think it can improve if I set the :<br />
format.setAlpha(true);<br />
instruction, or it has nothing to do with this?</p>
<p dir="auto">Regards,<br />
Bill</p>
]]></description><link>https://forum.qt.io/post/121042</link><guid isPermaLink="true">https://forum.qt.io/post/121042</guid><dc:creator><![CDATA[billouparis]]></dc:creator><pubDate>Mon, 19 Dec 2011 09:21:26 GMT</pubDate></item><item><title><![CDATA[Reply to [PARTIALLY SOLVED] QML &#x2F; ShadersEffectItem &#x2F; Transparency on Fri, 16 Dec 2011 21:38:27 GMT]]></title><description><![CDATA[<p dir="auto">No, not always. I've seen solutions that use offscreen OpenGL rendering with bliting into a transparent window, or enabling a platform specific extension. I haven't seen a solution that is implementable with the Qt APIs or one that is generally cross-platform. If someone knows one, I'd love to hear about it.</p>
]]></description><link>https://forum.qt.io/post/120849</link><guid isPermaLink="true">https://forum.qt.io/post/120849</guid><dc:creator><![CDATA[baysmith]]></dc:creator><pubDate>Fri, 16 Dec 2011 21:38:27 GMT</pubDate></item><item><title><![CDATA[Reply to [PARTIALLY SOLVED] QML &#x2F; ShadersEffectItem &#x2F; Transparency on Fri, 16 Dec 2011 21:28:07 GMT]]></title><description><![CDATA[<p dir="auto">Hopefully I will get a more encouraging answer than this one! I hope so, since generally does not mean always, right?</p>
]]></description><link>https://forum.qt.io/post/120847</link><guid isPermaLink="true">https://forum.qt.io/post/120847</guid><dc:creator><![CDATA[billouparis]]></dc:creator><pubDate>Fri, 16 Dec 2011 21:28:07 GMT</pubDate></item><item><title><![CDATA[Reply to [PARTIALLY SOLVED] QML &#x2F; ShadersEffectItem &#x2F; Transparency on Fri, 16 Dec 2011 19:57:43 GMT]]></title><description><![CDATA[<p dir="auto">Generally OpenGL windows (namely QGLWidget) don't support window transparency.</p>
]]></description><link>https://forum.qt.io/post/120837</link><guid isPermaLink="true">https://forum.qt.io/post/120837</guid><dc:creator><![CDATA[baysmith]]></dc:creator><pubDate>Fri, 16 Dec 2011 19:57:43 GMT</pubDate></item><item><title><![CDATA[Reply to [PARTIALLY SOLVED] QML &#x2F; ShadersEffectItem &#x2F; Transparency on Fri, 16 Dec 2011 14:38:31 GMT]]></title><description><![CDATA[<p dir="auto">Here is the illustration of what I would like to get on the left side of the image, and the result I am getting with my current code on the right side of the image. Anyone knows why?</p>
<p dir="auto">!<a href="http://i40.tinypic.com/29n9jxi.png" target="_blank" rel="noopener noreferrer nofollow ugc">http://i40.tinypic.com/29n9jxi.png</a>!</p>
]]></description><link>https://forum.qt.io/post/120809</link><guid isPermaLink="true">https://forum.qt.io/post/120809</guid><dc:creator><![CDATA[billouparis]]></dc:creator><pubDate>Fri, 16 Dec 2011 14:38:31 GMT</pubDate></item></channel></rss>