Problem with QGraphicsScene mouse move event
Hello,
I re-implement mouse event handlers in a subclass of QGraphicsScene and have a problem with the mouseMoveEvent() function.
The following code works (i.e. when I press the left/middle/right buttons, hold and move, I have the text displayed):
Code:
{
std::cout<<"hehe"<<std::endl;
}
but the following does not (nothing happens even if I press the left button):
Code:
{
if(e->button()==Qt::LeftButton) std::cout<<"hehe"<<std::endl;
}
The following code also works
Code:
if(e->button()==Qt::LeftButton) std::cout<<"hehe"<<std::endl;
}
Hope it's not a bug of Qt and somebody can help.
Thank you so much.
Re: Problem with QGraphicsScene mouse move event
QGraphicsSceneMouseEvent::button() returns the mouse button that causes the event to happen. Since mouse movement is not related to pressing a mouse button, button() probably returns Qt::NoButton. Try this instead:
Code:
if(e->buttons() & Qt::LeftButton) { ... }
Re: Problem with QGraphicsScene mouse move event
Works like a charm. Thanks, wysota :D