如何绘制具有透明度的 QPixmap
我有一个 QPixmap,我想将它绘制在 QWidget 上。但是,我想将其设置为 50% 透明,以便可以在下面看到背景。我怎样才能做到这一点?
I've got a QPixmap and I would like to draw it on a QWidget. However, I would like to make it 50% transparent so that the background can be seen below. How can I do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在 QPainter 中设置合成模式,然后使用掩码来定义哪些位iage 的部分是透明的,或者对设置了 alpha 通道的图像使用 QImage::Format_ARGB32_Premultiplied 类型。
请参阅示例 http://doc.qt.io/archives/4.6/demos-组成.html
You set the compositionmode in the QPainter and then either use a mask to define which bits of the iage are transparent or use QImage::Format_ARGB32_Premultiplied type for the image with the alpha channel set.
See the example http://doc.qt.io/archives/4.6/demos-composition.html