I am writing a little utill for me on ruby using qt. How to access global mouse movement and keyboard input events?
+2
A:
Use QWidget::grabMouse() and note that its a very dangerous function, use it with care.
cartman
2009-05-21 11:43:26
Why is it dangerous?
pez_dispenser
2009-05-21 15:00:00
+3
A:
If you need to track mouse movement when no buttons are clicked, you'll want to turn on mouse tracking on the widget(s) you wish to track the mouse on. The function QWidget::setMouseTracking()
, available on all QWidget
s, will let you do this.
To capture mouse movements, you'll need to capture QMouseMoveEvent
s. There are two ways to do this:
- If you are defining your own widget, then reimplement
QWidget::mouseMoveEvent()
. - If you are using a stock widget, then you can create an event filter class and install an event filter on the widget you'd like to track mouse movements. See
QObject::installEventFilter()
.
For official Qt documentation, click the links on the functions of interest.
swongu
2009-05-21 21:09:25