简体   繁体   English

PyQt5透明窗口错误?

[英]PyQt5 Transparent Window Bug?

I've been working on a screenshot application written in Python (v. 3.5) using PyQt5 (v 5.7), but I've been developing it on MacOs. 我一直在使用PyQt5(v.5.7)编写用Python编写的截图应用程序(v.5.5),但我一直在MacOs上开发它。 The app works as intended on Mac, but when I pulled the repo onto my Windows 10 machine I can't get the app to render properly. 该应用程序在Mac上按预期工作,但当我将repo拉到我的Windows 10机器上时,我无法正确呈现应用程序。

Basically I want a fullscreen transparent window, here's the code I am using. 基本上我想要一个全屏透明窗口,这是我正在使用的代码。 As it is, nothing renders at all. 事实上,根本没有渲染。 ( Qt is imported from QtCore ) QtQtCore导入)

    self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
    self.setAttribute(Qt.WA_TranslucentBackground)
#Maximize the window
    self.showFullScreen()
#Render the window
    self.activateWindow()
    self.setFocus()
    self.show()

When I comment out self.setAttribute(Qt.WA_TranslucentBackground) it will actually render (but with the gray-ish background). 当我注释掉self.setAttribute(Qt.WA_TranslucentBackground) ,它将实际呈现(但具有灰色背景)。

I've tried removing self.windowFlags() from setWindowFlags() to no avail (as seen in this answer). 我试图消除self.windowFlags()setWindowFlags()无济于事(在看到这个答案)。

Also tried it without self.setFocus() and self.activateWindow() 还试过没有self.setFocus()self.activateWindow()

Is this a bug? 这是一个错误吗? or am I doing something wrong here. 或者我在这里做错了什么。

Any help would be appreciated. 任何帮助,将不胜感激。

Try using the windowOpacity prop or method setWindowOpacity(double) 尝试使用windowOpacity prop或方法setWindowOpacity(double)

http://doc.qt.io/qt-5/qwidget.html#windowOpacity-prop http://doc.qt.io/qt-5/qwidget.html#windowOpacity-prop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM