How to make a click through PyQt windows

I would like to make a window in PyQt that you can click; those. click on the window and click on it so you can interact with what is behind it while the window stays on top. An example of an effect I'm trying to achieve is similar to the notifications on Ubuntu, which are displayed in the upper right corner by default, which you can click.

I would like to be able to do this in PyQt ideally; if not, my platform is Linux, but Windows solutions are also welcome!

Welcome help in advance! I give this a little thought and research, it would be great to do it.

EDIT: I am trying to create a window that you can use, for example, as onion skin for the window behind

+2


source to share


1 answer


Here is a solution on Windows using PyQt4.

You need to override the eventFilter in the Front widget (on Windows it is winEvent) and then forward the events to the Back window.

I'm not entirely sure, but there should be a similar approach that can be used on other platforms (instead of winEvent, maybe x11Event?)



Good luck!

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

      

+1


source







All Articles