Search code examples
c++qtqt4transparency

Transpaprent QLabel


#include <QtGui>

class   Label : public QLabel
{
public:
    Label(QWidget *parent =0) :
        QLabel(parent)
    {
        resize(100, 100);
        setText("hello");
        show();
    }
};

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    Label l;

    return a.exec();
}

This outputs a label 'hello' with a background. I'm using Qt4. I want to make the background of this label completely transparent. But setWindowOpacity changes the whole widget transparency. I want the content as it is, but only the background to be transparent.


Solution

  • I found this as simpler....

    QWidget::setAttribute(Qt::WA_TranslucentBackground);