我有一个带有 QLabel 和像素图的主窗口。我想让它透明(或不那么不透明)
我正在使用下面的代码。
ui->label->setAttribute(Qt::WA_TranslucentBackground);
ui->label->repaint();
然而它似乎不起作用。图像看起来没有任何变化。我还尝试使用以下语句:
ui->label->setStyleSheet("background-color: rgba(255, 255, 255, 10);");
不幸的是,这似乎也不起作用。
有人知道如何使图像透明或减少不透明吗?
感谢您的时间。
如果您的图像不是透明的,而您希望它是透明的,您可以执行以下操作:
QLabel *l = new QLabel(this);
QImage image(":/img/myimage.png");
QPainter p;
p.begin(&image);
p.setCompositionMode(QPainter::CompositionMode_DestinationIn);
p.fillRect(image.rect(), QColor(0, 0, 0, 50));
p.end();
l->setPixmap(QPixmap::fromImage(image));
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)