[solved] how to get an simple transparent window
Hi, I try to build a simple MainWindow which has an transparent background.
I saw so many approaches out there but nothing works.
Some How to's arn't working and others are ...
"This":http://developer.qt.nokia.com/faq/answer/how_can_i_have_a_partially_transparent_pixmap_on_my_toplevel_window for example isn't really useful or ?
Do I have a chance to just get the background of my main window transparent without hacking around ?
I know that there is a way with masks but I didn't get this to work.
Do anybody has an example of how to do that the right way.
The following worked for me. Do it in the constructor of your MainWindow:
The only problem that I am facing with that is: On KDE4 I have enabled window shadows. The code above makes the window transparent, but the shadow remains visible... =)
Heh, ok I will try this and the shadow thing should be no problem because I set a QDeclarativeView as centralWidget I just don't want the Widget based window to be appear. So it could look like my qml window is shadowing.
Hope this will work. When I try to use a Mask all I get is a black window background.
Ok I tried this out and it seems to work partially, the mainWindow on its own disapear but If I have
a Widget on that window it looks like I loose the opacity effect.
I have a QDeclarativeView as Centralwidget with an area that is halfway transparent but I can't look through the underlying mainWindow the transparency effect is gone.
How can I fix that ?
Do I have to get the QDeclarativeView to be transparent too ?
I tried this already but it doesn't seem to work.
I am not quite sure what you want to do, but for me it works like that (in the Constructor of the MainWindow):
QDeclarativeView* v = new QDeclarativeView;
v->setSource(QUrl("qrc:/test.qml")); v->setStyleSheet("background:transparent"); v->setAttribute(Qt::WA_TranslucentBackground); v->setWindowFlags(Qt::FramelessWindowHint); setStyleSheet("background:transparent;"); setAttribute(Qt::WA_TranslucentBackground); setWindowFlags(Qt::FramelessWindowHint);@
using the following QML from the documentation:
@import Qt 4.7
width: 100; height: 100
x: 50; y: 50; width: 100; height: 100
Hey thank you Markus, your example works perfectly, this is exactly what I was searching for.
two Thumbs up !!
Nice! =) Glad to be of help.
If you want to, you can edit your original post title and add a [solved] in front. So others know that the topic is solved by looking at the title.
Sorry to bump it up, but I have posted a question and haven't got an answer yet. The solution with Qt::WA_TranslucentBackground works fine, but my widget has other sub-widgets (QImages) rendered through OpenGL, and using this property on the parent widget makes those images appear blank in Windows. Is there any other way of achieving this, i.e, without using Qt::WA_TranslucentBackground, even if it has to be rather hackish?