c++ - Transparent widget with QtQuick 2.0 -
i'am trying create transparent window qtquick 2.0.
i can create transparent widget that:
class transparentwidget : public qwidget { public:     transparentwidget(qwidget* parent)     : qwidget(parent)     {         resize(qsize(500, 500));         setattribute(qt::wa_translucentbackground);         setwindowflags(qt::framelesswindowhint);     }      void paintevent(qpaintevent * event)     {         qpainter painter;         qbrush brush(qt::cyan);         painter.begin(this);         painter.setrenderhint(qpainter::antialiasing);         painter.setbrush(brush);         painter.drawrect(0,0,100,100);         painter.end();     } };   now want same thing qquickview, first create it:
qquickview view; view.setsource(qurl::fromlocalfile("test.qml")); view.setresizemode(qquickview::sizerootobjecttoview);    and here "test.qml" file:
rectangle {     width: 300;     height: 300;     color: "transparent";      rectangle     {         anchors.top: parent.top;         anchors.left: parent.left;         width: 50;         height: 100;         color: "lightsteelblue";     }      rectangle     {         anchors.bottom: parent.bottom;         anchors.right: parent.right;         width: 50;         height: 100;         color: "darkgrey";     } }   now want create transparent widget , did that:
qwidget *p = qwidget::createwindowcontainer(&view, null, qt::framelesswindowhint); p->setattribute(qt::wa_translucentbackground); p->show();   i create widget wa_transeculentbackground , framelesswindowhint way did previous 1 didn't work.
than go little deeper , used pix see whats qquickview calling behind , see line:

now questions:
1 - why qt calling idirect3ddevice9::clear color white?
2- there way tell qquickview or qmlengine not draw background anything?
transparency qtquick2 works since qt 5.2, @ least windows (both angle , opengl builds):
create view:
qquickview view; view.setopacity(0.9999); view.setcolor( qt::transparent ); view.setsource( qurl::fromlocalfile( qlatin1string( "main.qml" ) ) );   no additional style/attribute/flag calls needed besides setopacity , setcolor. "main.qml" must set transparency properly, qml example does:
rectangle {     color: "transparent" }      
Comments
Post a Comment