Important: Please read the Qt Code of Conduct -

[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": 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:

    @ setStyleSheet("background:transparent;");

    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.

  • Hi.

    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;


    using the following QML from the documentation:

    @import Qt 4.7

    Item {
    Rectangle {
    opacity: 0.5
    color: "red"
    width: 100; height: 100
    Rectangle {
    color: "blue"
    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?

Log in to reply