Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect the mouse state in Qt without a MouseEvent

Tags:

c++

qt

mouse

qt3

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).

like image 762
Jonathan M Davis Avatar asked Aug 21 '09 15:08

Jonathan M Davis


1 Answers

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.

like image 55
Bill Avatar answered Oct 16 '22 13:10

Bill