#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.
5 Réponses :
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);
Vous pouvez utiliser des feuilles de style pour définir la couleur et la valeur alpha de l'arrière-plan:
J'ai trouvé cela comme plus simple ....
QWidget::setAttribute(Qt::WA_TranslucentBackground);
en pyqt: p>
lbl.settattribute (qt.wa_transluctère, true) p> blockQuote>
Dans mon cas avec qt5, les suivants ont fonctionné: testé à la fois avec Qt 5.111.1 et QT 5.8.0. P> P>
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.