Qt how to check which mouse button is pressed

Alex picture Alex · May 26, 2013 · Viewed 36.6k times · Source

I have problems in PySide while trying to determine which mouse button is pressed in event function. I need it in particular for ignoring mouse move event, because it's doing job on both mouse buttons, left and right.

I want to ignore mouse move event if the right button on scene is pressed. Any help?

Answer

fasked picture fasked · May 27, 2013

All of mouse events have two methods (button and buttons) to determine which of buttons are pressed. But for only move event the documentation says:

Note that the returned value is always Qt::NoButton for mouse move events.

for mouseMoveEvent you should use buttons method.

void mouseMoveEvent(QMouseEvent *e)
{
    if(e->buttons() == Qt::RightButton)
        qDebug() << "Only right button";
}

In order to ignore move events you need to do this work in eventFilter of course.