Reputation: 2018
i'm developing a Qt application, I know that there is a wheelEvent to get the wheel's state, but I can't find how to know if the wheel is pressed. thanks !
Upvotes: 3
Views: 3722
Reputation: 22890
The wheel event set up the buttons which are being pressed. It also set the keyboard modifier keys which are pressed (eg. SHIFT
, CRTL
).
void MyWidget::wheelEvent ( QWheelEvent * event )
{
if(event->buttons() & Qt::MiddleButton != 0)
{
//the mid button is being pressed. handle.
}
}
Here is a list of possible buttons. They are set as flags, i.e Qt::LeftButton | Qt::RightButton
Edit:
The wheel is associated by default to the middle button. The wheel can move without an associated button in the wheel event. For instance, on chrome browsers moving the wheel scrolls. Pressing the wheel will change the cursor on the screen as well as the behavior of the wheel(try it).
If you have a weird mouse with a wheel and a middle button:
MouseEvent
with Qt::MiddleButton
WheelEvent
with Qt::MiddleButton
.Upvotes: 3
Reputation: 9156
Look in the documentation of QMouseEvent. Catch that event and watch out for the third mouse button.
If you are not interested in an event but the state of the button you also may be interested in QGuiApplication::mouseButtons().
Upvotes: 0