1

I am writing Qt application which plays a fade-in animation whenever the mouse is moved to a certain area in the screen, and a fade out animation whenever the mouse is moved out of that same area.

I've already found a similar question here in stack overflow, however, it does not quite answer my question. (similar question here)

If I install an event filter to the application, will I be able to see ALL the events in the application even if it's outside my widget window?

If not, I am aware of an alternative involving QWidget::grabMouse() inside a reimplementation of leaveEvent(). But if I do so, will I be able to interact with anything OUTSIDE my application?

edit: though i am using the Qt library, my application is only for deployment to Windows.

Subaru Tashiro
  • 2,166
  • 1
  • 14
  • 29
  • Prompted by the other responses here, can you clarify if your app is cross-platform, or specific to a particular OS? – cmannett85 Dec 15 '11 at 14:11

3 Answers3

5

I'm fairly the certain the answer is no, because events outside of your widgets are handled by the OSs window manager (and propagated onto whatever application is in that space).

However you can get the mouse position anywhere on the screen by calling QCursor::pos(), you could poll at regular intervals to find out where the mouse is.

cmannett85
  • 21,725
  • 8
  • 76
  • 119
  • i see, what would be an efficient way to do this? Should i just use QObject::startTimer() and reimplement timerEvent()? Or use QTimer and connect it's timeout() signal to a slot? – Subaru Tashiro Dec 15 '11 at 13:07
  • I haven't used `QObject::startTimer()`, so I can't answer that - although I imagine either option is equivalent. I think finding a balanced time interval will be more important at this stage. – cmannett85 Dec 15 '11 at 13:20
2

You could try creating a completely transparent window that stays on top of the area where you want to receive mouse events, with the Qt::WindowStaysOnTopHint, Qt::FramelessWindowHint and Qt::ToolTip flags (the last one might prevent the window from receiving the focus), the Qt::WA_TranslucentBackground attribute and the mouse tracking enabled.

alexisdm
  • 29,448
  • 6
  • 64
  • 99
1

If you are on Windows, you can create a global hook to receive every mouse message (right before it's sent to the window under the mouse pointer). Unfortunately I don't know whether this functionality exists in other OSs.

kol
  • 27,881
  • 12
  • 83
  • 120