Using an alpha transparent mask on a QWidget?

别来无恙 提交于 2019-12-02 01:14:07
sam-w

I think your best route is in QPainter's composition modes.

For example:

QPixmap PixmapToBeMasked(Size);
PixmapToBeMasked.fill(QColor(255, 255, 255, 120));

QPixmap Mask = DoSomethingToGetAMask();

QPainter Painter(&PixmapToBeMasked);
Painter.setCompositionMode(QPainter::CompositionMode_DestinationIn);
Painter.drawPixmap(0, 0, Mask.width(), Mask.height(), Mask);

That will handle drawing your widget nicely. If you still need to mask mouse events you might need to do some extra work though.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!