11
votes

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.

2 commentaires

Il y a un article intitulé "Fonds transparents dans Qt 4.1" ici: doc.qt.nokia .com / qq / qq16-fond.html va-t-il fonctionner pour vous?


@aldo - Le document Nokia n'existe plus en ligne.


5 Réponses :


2
votes

Si vous définissez un qcolor code> avec alpha de 0 code> Vous obtiendrez de l'arrière-plan avec une couleur transparente, donc par exemple:

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


0 commentaires

14
votes

Vous pouvez utiliser des feuilles de style pour définir la couleur et la valeur alpha de l'arrière-plan: xxx


0 commentaires

26
votes

J'ai trouvé cela comme plus simple ....

QWidget::setAttribute(Qt::WA_TranslucentBackground);


0 commentaires

4
votes

en pyqt:

lbl.settattribute (qt.wa_transluctère, true)


0 commentaires

2
votes

Dans mon cas avec qt5, les suivants ont fonctionné: xxx

testé à la fois avec Qt 5.111.1 et QT 5.8.0.


0 commentaires