Reputation: 535
I am wondering how i can distinguish wheel click event from mouse press event. Because i want to do different handling for these two events in pyside. Currently, every time I click the wheel button, the event is catched by mousepressevent. Can anyone explain ?
Edit: I want to implement this in a subclass of qglwidget class
Upvotes: 1
Views: 4912
Reputation: 1733
From its name, the mousePressEvent
is responsible for mouse clicks while the wheelEvent
is for scrolling solely. The wheelEvent
will not catch the wheel button click. It is how the Qt's API is designed when it comes to mouse events processing.
In order to separate which mouse button is pressed (right, wheel or left), use button
property of QMouseEvent
.
This is how the code would look like using C++ (I imagine it is easy to translate it to pyside
)
void GLWidget::mousePressEvent(QMouseEvent *event) // redefine the mouse event
{
switch( event->button() ) {
case Qt::LeftButton:
// do stuff for left button pressed
break;
case Qt::MiddleButton:
// do stuff for wheel button pressed
break;
// ...
}
}
So, for pyside, you only need to compare the button
property of event
in mousePressEvent
and see whether it is Qt.LeftButton
, Qt.RightButton
or Qt.MidButton
. Hope that helps.
Upvotes: 6