QWidget的每像素透光度

QWidget per-pixel translusency

本文关键字:像素 QWidget      更新时间:2023-10-16

我正在考虑制作一个部分半透明的QWidget。

QWidget::setMask可以设置每像素的透明度,就像这样,但它是非此即彼:不是半透明的。

QWidget::opacity可以设置全局透明度,但不是按像素设置。

我如何才能获得两全其美,并为整个小部件添加逐像素alpha通道?(装饰不重要)

也许QWidget::setMaks()?

QLabel topLevelLabel;
QPixmap pixmap(":/images/tux.png");
topLevelLabel.setPixmap(pixmap);
topLevelLabel.setMask(pixmap.mask());

它看起来像QStyle类是你可能正在寻找的,特别是QStyle:: drawwitempixmap;然后使用QWidget::setStyle()。不过我自己从来没用过。