具有透明背景的 Qt 小部件 [英] Qt Widget with Transparent Background

查看:46
本文介绍了具有透明背景的 Qt 小部件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(我正在使用 PySide,但我认为任何语言绑定的答案都是相同/相似的).

(I'm using PySide, but I think the answer would be the same/similar for any language bindings).

我正在尝试以形状时钟为例,位于 在这里,并使时钟(圆圈)的表面变得透明,以便我看到的只是时钟指针和分钟刻度.照原样,当示例运行时,它看起来像 this.我使用的是 Windows 7.

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)
    • 时钟出现(在任务栏中有),但我在任何地方都看不到它
    • 时钟出现,但背景为纯黑色.
    • 时钟出现,但整个时钟是透明的.我希望背景(面)透明,但我希望时钟指针可见.

    推荐答案

    知道了!

    这是来自原始示例代码(构造函数):

    This is from the original example code (constructor):

        ...
        self.setWindowFlags(self.windowFlags() | QtCore.Qt.FramelessWindowHint)
        ...
    

    这是修改后的(根据我的问题工作)版本:

    Here is the modified (and working per my question) version:

        ...
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint)
        self.setAttribute(QtCore.Qt.WA_TranslucentBackground)
        ...
    

    删除 self.windowFlags() 是我缺少的部分.(我不确定为什么我需要删除它,或者为什么它一开始就在那里......还有很多东西需要学习).

    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).

    这篇关于具有透明背景的 Qt 小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆