Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt - Draw a fully transparent window in Windows without using WA_TranslucentBackground

I need to draw transparent window (either QLabel or QFrame or QWidget), but without using WA_TranslucentBackground. The reason for that is that the windows will contain other child widgets rendered through OpenGL, and using that property makes those windows invisible on Windows, as documented here. This works fine in Mac though, I need a different solution on Windows only, as it does not work there. I tried this: setting a blank pixmap. But it still shows up with a grey background:

#include <QApplication>
#include <QLabel>
#include <QBitmap>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    QLabel l;
    l.setWindowFlags(Qt::FramelessWindowHint);
    QPixmap p("");
    l.setPixmap(p);
    l.setScaledContents(true);
    l.resize(300, 500); //just to test my idea
    l.setMask(p.scaled(l.width(),l.height(),Qt::IgnoreAspectRatio,
    Qt::SmoothTransformation).mask());
    l.show();
    return a.exec();
}

Can anyone suggest any other means of achieving this on Windows, i.e a fully transparent window? Platform - Qt 5.3.1, 32 bit.

P.S - It need not behave like translucent window, i.e where the background can be clicked through the transparent parts of a widget rendered though WA_TranslucentBackground. Here as long as it is transparent it will be okay, it need not be clickable 'through'.

like image 363
SexyBeast Avatar asked Jan 11 '16 04:01

SexyBeast


1 Answers

I am on Windows (Qt 5) and use the following to create a Semi-Transparent Widget:

setWindowOpacity(0.6);
setStyleSheet("QWidget{background: #000000}")

It should work if you set the opacity to zero. I use this together with the Windows flags "framelessWindow" and "Tool" to darken the background of the screen.

like image 197
Mailerdaimon Avatar answered Sep 26 '22 00:09

Mailerdaimon