具有透明背景的 Qt 小部件
(我正在使用 PySide,但我认为对于任何语言绑定来说答案都是相同/相似的)。
我正在尝试采用形状时钟示例,位于此处,并使钟面(圆圈)透明,以便我看到的只是钟针和分钟滴答声。事实上,当示例运行时,它看起来像 this。我使用的是 Windows 7。
到目前为止,我已经尝试了以下操作(在构造函数中):
- self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
- 时钟出现(出现在任务栏中),但我在任何地方都看不到它
self.setAttribute(QtCore.Qt.WA_NoSystemBackground)
- 出现时钟,但背景为纯黑色。
self.setWindowOpacity(0.5)
- 时钟出现,但整个时钟是透明的。我希望背景(脸部)是透明的,但我希望时钟指针可见。
(I'm using PySide, but I think the answer would be the same/similar for any language bindings).
I'm trying to take the shaped clock example, located here, and cause the face of the clock (circle) to be transparent so that all I see are the clock hands and minute ticks. As is, when the example runs, it looks like this. I'm using Windows 7.
So far, I've tried the following (in the constructor):
self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
- Clock appears (has presence in task bar), but I can't see it anywhere
self.setAttribute(QtCore.Qt.WA_NoSystemBackground)
- Clock appears, but has solid black background.
self.setWindowOpacity(0.5)
- Clock appears, but entire clock is transparent. I want the background (face) to be transparent, but I want the clock hands to be visible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
知道了!
这是来自原始示例代码(构造函数):
这是修改后的(并根据我的问题工作)版本:
删除
self.windowFlags()
是我缺少的部分。 (我不太确定为什么我需要删除它或者为什么它一开始就在那里......还有很多东西需要学习)。Got it!
This is from the original example code (constructor):
Here is the modified (and working per my question) version:
Removing the
self.windowFlags()
was the part I was missing. (I'm not exactly sure why I needed to remove this or why it was there to begin with... still much to learn).如果我没记错的话,你应该也设置它的样式表:
希望有帮助。
If I remember correctly, you should have set its stylesheet also:
Hope that helps.
在时钟示例中有:
setMask
做圆形。但 PySide 中也有同样的功能:
所以它也应该可以工作吗?
In the clock example there is:
The
setMask
do the round shape.But there's the same in PySide:
so it should work too?