Python 如何通过windows PyQt进行单击
我想在PyQt中创建一个窗口,您可以点击它;ie点击一个窗口,点击就会被传递出去,这样你就可以在窗口保持在顶部的同时与它后面的任何东西进行交互。我试图达到的效果的一个例子是,Ubuntu上的通知默认显示在右上角,你可以点击它 我希望能够做到这一点在PyQt理想;如果不是,我的平台是linux,但也欢迎windows解决方案 为提前的帮助干杯!我已经对此进行了一些思考和研究,能够做到这一点将是非常棒的Python 如何通过windows PyQt进行单击,python,click,pyqt,Python,Click,Pyqt,我想在PyQt中创建一个窗口,您可以点击它;ie点击一个窗口,点击就会被传递出去,这样你就可以在窗口保持在顶部的同时与它后面的任何东西进行交互。我试图达到的效果的一个例子是,Ubuntu上的通知默认显示在右上角,你可以点击它 我希望能够做到这一点在PyQt理想;如果不是,我的平台是linux,但也欢迎windows解决方案 为提前的帮助干杯!我已经对此进行了一些思考和研究,能够做到这一点将是非常棒的 编辑:我正在尝试制作一个窗口,你可以像跟踪纸一样为后面的窗口使用这里有一个使用PyQt4的Win
编辑:我正在尝试制作一个窗口,你可以像跟踪纸一样为后面的窗口使用这里有一个使用PyQt4的Windows解决方案 您需要覆盖前窗口小部件中的eventFilter(在Windows上是winEvent),然后将事件转发到后窗口 我不完全确定,但必须有一种类似的方法可以在其他平台上使用(而不是winEvent,可能是x11Event?) 祝你好运
from PyQt4 import QtCore, QtGui
import win32api, win32con, win32gui, win32ui
class Front(QtGui.QPushButton):
def __init__(self,text="",whndl=None):
super(Front,self).__init__(text)
self.pycwnd = win32ui.CreateWindowFromHandle(whndl)
# install an event filter for Windows' messages. Forward messages to
# the other HWND
def winEvent(self,MSG):
# forward Left button down message to the other window. Not sure
# what you want to do exactly, so I'm only showing a left button click. You could
if MSG.message == win32con.WM_LBUTTONDOWN or \
MSG.message == win32con.WM_LBUTTONUP:
print "left click in front window"
self.pycwnd.SendMessage(MSG.message, MSG.wParam, MSG.lParam)
return True, 0 # tells Qt to ignore the message
return super(Front,self).winEvent(MSG)
class Back(QtGui.QPushButton):
def __init__(self,text=""):
super(Back,self).__init__(text)
self.clicked.connect(self.onClick)
def onClick(self):
print 'back has been clicked'
def main():
a = QtGui.QApplication([])
back = Back("I'm in back...")
back.setWindowTitle("I'm in back...")
back.show()
# Get the HWND of the window in back (You need to use the exact title of that window)
whndl = win32gui.FindWindowEx(0, 0, None, "I'm in back...")
# I'm just making the front button bigger so that it is obvious it is in front ...
front = Front(text="*____________________________*",whndl=whndl)
front.setWindowOpacity(0.8)
front.show()
a.exec_()
if __name__ == "__main__":
main()
这很有效。它在Linux Mint 20.1肉桂上进行了测试。
这意味着家长一直阻止它
WA_TransparentForMouseEvents
这两个窗口(通知和它后面的窗口)属于同一个应用程序吗?不,点击式窗口后面的窗口可以是任何窗口,这可能会使它更难!干杯!只是在windows上试一试,效果很好。你是我的英雄。没问题——这是一个很好的挑战!我确实使用了一种稍微不同的方法将其改编为x11,我会在有机会时发布它
self.setAttribute(Qt.WA_TransparentForMouseEvents, True)
self.setAttribute(Qt.WA_NoChildEventsForParent, True)
self.setWindowFlags(Qt.Window|Qt.X11BypassWindowManagerHint|Qt.WindowStaysOnTopHint|Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)