1


In a Python program I want to draw a (possibly shaped) overlay window under the mouse pointer, that should follow it (I already have the code to get its new coordinates on mousemove) and must not interfere with clicks to other windows. My target platform is Linux (KDE) but if it's cross platform it's better. How can I do it, for example with Tkinter or PyQT?
Thanks in advance for the answers
EDIT: I forgot to say that the window should support transparency (it will be an alpha blended circle around the mouse pointer)

Lord Spectre
  • 761
  • 1
  • 6
  • 21

1 Answers1

1

In PyQt, you can create any QWidget to show as a window and use QWidget.setGeometry() to set its position on screen.

You can read the documentation on background transparency: http://qt-project.org/doc/qt-4.8/qwidget.html#autoFillBackground-prop

..and this question to get rid of the window borders: How to remove the window border (containing minimize, maximize and close buttons) from a Qt widget?

To avoid catching mouse clicks, though, could be difficult. The simplest solution might be to use QWidget.setMask or perhaps Qt::WA_TransparentForMouseEvents (see first link above), but I'm betting at some level this is up to the OS's window manager and out of the control of your program. One possible workaround might be to break up your interface into separate windows that are tiled around the cursor.

Community
  • 1
  • 1
Luke
  • 11,374
  • 2
  • 48
  • 61
  • But I need to "transfer" the click under my overlay window, as if it wasn't there... – Lord Spectre Aug 06 '12 at 23:20
  • Now THAT's tricky. See my updated answer. – Luke Aug 07 '12 at 01:58
  • I'll try, but I'm quite new to PyQt... – Lord Spectre Aug 07 '12 at 08:46
  • I have some problem moving the (for now plain empty) QWidget with win.move(x,y), it seems that it's cached and it is applied only at a regular interval. The same happens with setGeometry. – Lord Spectre Aug 07 '12 at 09:23
  • perhaps try calling QApplication.processEvents() immediately after the call to setGeometry? – Luke Aug 07 '12 at 12:16
  • Now it only moves when the pointer is already over it (but not when first started or when it goes under another window or the panel). Also I cannot make it transparent, and WA_TransparentForMouseEvents doesn't make it "transparent for mouse events" – Lord Spectre Aug 07 '12 at 12:21
  • How are you getting the mouse position? You can always use QCursor.pos(), but you would have to set up a loop to poll for position changes. To keep the window on top, see Qt::WindowStaysOnTopHint. For more info on transparent windows, try this: http://stackoverflow.com/questions/1909092/qt4-transparent-window-with-rounded-corners – Luke Aug 07 '12 at 15:32
  • Does QCursor.pos give me the position relative to the desktop or the window? Anyway I use PyMouse that automatically listens to Xorg mousemove events and calls a function passing the coordinates. The function is called because I check it with a print statement in it. – Lord Spectre Aug 07 '12 at 16:04
  • QCursor gives you desktop coordinates, but PyMouse should work just as well.. – Luke Aug 07 '12 at 19:12