如何设置QWindow对鼠标等事件透明?

How to set QWindow to be transparent to mouse and other events?

我正在构建一个叠加层以在全屏应用程序上显示 OBS 流统计信息。 我已经通过将 windows 标志设置为:WindowStaysOnTopHint | FramelessWindowHint X11BypassWindowManagerHint)

来实现它的视觉部分

问题是此 window 响应鼠标(悬停时将光标更改为系统一)并阻止点击操作。我发现 WA_TransparentForMouseEventsWA_TranslucentBackground 会有帮助,但没有帮助。

from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.QtCore import Qt
app = QApplication([])
window = QWidget()
window.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint )#| Qt.X11BypassWindowManagerHint)
window.setAttribute(Qt.WA_TransparentForMouseEvents,True)
window.setAttribute(Qt.WA_TranslucentBackground,True)
window.show()
app.exec()

如何让QtWindow对鼠标和其他事件透明。在其他作品中充当适当的叠加层。

需要设置的flag是:

Qt::WindowTransparentForInput

Informs the window system that this window is used only for output (displaying something) and does not take input. Therefore input events should pass through as if it wasn't there.

https://doc.qt.io/qt-5/qt.html#WindowType-enum