I want to be able to drag my semi-transparent application window around the screen and "drop" it onto whichever window is under the pointer when I let go. At this point I want my GUI window to reconfigure itself to be congruent with the target window. It would also be nice to cause the target window to come out from behind all windows except mine.
Well, finally, I have some code to share. It works, mostly, but it doesn't always grab the entire target window. Sometimes it grabs only a portion of it. If you have any ideas, lay them on me, please. To activate a grab, I drag my window somewhere over the target, move the mouse pointer anywhere in the region where they overlap, and type "w." Type "w" again to restore my window to its previous state. It took me a long time to figure this out because I am a rank beginner. In the end the resolution turned to be surprisingly straightforward, I think. But, I would appreciate any help to streamline the code. It has a kludgy feel to it. Thanks in advance.
if (e.key() == Qt.Key_W):
if (self.makeBaby):
self.makeBaby = False
self.setGeometry(self.previousGeometry)
self.updateStuff() #> Redraw everything after getting <#
#> off her. How do you know it's a <#
#> girl? Her mouth is open. <#
else:
self.makeBaby = True
Joe = self.geometry()
self.previousGeometry = Joe
self.windowHandle = win32gui.WindowFromPoint((QCursor.pos().x(), QCursor.pos().y()))
#> Get my window's handle. <#
self.move(self.ws, self.hs)
#> Get out of the way. <#
windowHandle = win32gui.WindowFromPoint((QCursor.pos().x(), QCursor.pos().y()))
#> Get the target window's handle. <#
windowRect = win32gui.GetWindowRect(windowHandle)
#> Get its geometry. <#
x = windowRect[0]
y = windowRect[1]
w = windowRect[2] - x
h = windowRect[3] - y
self.move(Joe.x(), Joe.y())
#> Return to the playing field. <#
win32gui.SetWindowPos (windowHandle, self.windowHandle, x, y, w, h, win32con.SWP_NOSIZE|win32con.SWP_NOMOVE)
#> Position the target window under <#
#> my window. <#
self.raise_() #> This and the next line are <#
#> necessary. I don't understand why. <#
self.activateWindow()
self.setGeometry(x, y, w, h)
#> Match my window's geometry to the <#
#> target's. <#
self.updateStuff() #> Give her a new coat of paint. <#