Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt how to check which mouse button is pressed

Tags:

c++

qt

pyqt

pyside

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?

like image 434
Alex Avatar asked May 26 '13 13:05

Alex


1 Answers

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.

like image 136
fasked Avatar answered Oct 03 '22 06:10

fasked