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 displays the label "hello" with the background. I am using Qt4. I want to make the background of this shortcut completely transparent. But setWindowOpacity changes the entire transparency of the widget. I want the content to be what it is, but only the background should be transparent.

+5
source share
4 answers

I found it easier ...

QWidget::setAttribute(Qt::WA_TranslucentBackground);
+12
source

You can use style sheets to set the background color and alpha value:

setStyleSheet("background-color: rgba(0,0,0,0%)");
+8
source

If you define QColorwith alpha 0, you get a background with a transparent color, for example:

QColor bg_color(255, 0, 0, 0);
QPalette p(l.palette());
p.setColor(QPalette::BackgroundColor, bg_color);
l.setPalette(p);

What should make the background shortcut any transparent color.

0
source

In PyQt:

lbl.setAttribute (Qt.WA_TranslucentBackground, True)

0
source

All Articles