Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 638
Dewsworld Avatar asked Mar 31 '12 02:03

Dewsworld


2 Answers

You can use stylesheets to set the color and the alpha value of the background:

setStyleSheet("background-color: rgba(0,0,0,0%)");
like image 63
riv333 Avatar answered Sep 19 '22 20:09

riv333


I found this as simpler....

QWidget::setAttribute(Qt::WA_TranslucentBackground);
like image 41
Dewsworld Avatar answered Sep 18 '22 20:09

Dewsworld