How to detect the mouse state in Qt without a MouseEvent


Okay, using Qt, I'd like to know how to detect the current state of the mouse at any point in time - without a MouseEvent.

Using QCursor::pos(), you can get its position, but is there a way to determine the current state of the buttons?

Basically, I'm looking to verify the state of the mouse when a timer goes off, so it won't be related to any particular MouseEvent, and so there's no MouseEvent to query. I need to know how to query for the mouse's state - in particular the state of the buttons - without having a MouseEvent.

Oh, and I'm using Qt 3, so if such a function has been added in Qt 4 but isn't in Qt 3, it doesn't help me much (though it would still be nice to know about).

8/21/2009 5:16:28 PM

Qt::MouseButtons QApplication::mouseButtons () [static]:

Returns the current state of the buttons on the mouse. The current state is updated syncronously as the event queue is emptied of events that will spontaneously change the mouse state (QEvent::MousePress and QEvent::MouseRelease events).

It should be noted this may not reflect the actual buttons held on theinput device at the time of calling but rather the mouse buttons as last reported in one of the above events. If no mouse buttons are being held Qt::NoButton is returned.

Edit: hmm, I just noticed you asked about Qt3.3. This answer applies to Qt4 I'm afraid.

12/4/2017 8:41:50 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow