Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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):
    @void Scene::mouseMoveEvent(QGraphicsSceneMouseEvent* e)
    {
    std::cout<<"hehe"<<std::endl;
    }@

    but the following does not (nothing happens even if I press the left button):
    @void Scene::mouseMoveEvent(QGraphicsSceneMouseEvent* e)
    {
    if(e->button()==Qt::LeftButton) std::cout<<"hehe"<<std::endl;
    }@

    The following code also works
    @void Scene::mousePressEvent(QGraphicsSceneMouseEvent* e){
    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.



  • "QGraphicsSceneMouseEvent::button":http://qt-project.org/doc/qt-4.8/qgraphicsscenemouseevent.html#button

    bq. Returns the mouse button (if any) that caused the event.

    So left click button had caused the event.
    You can use:
    @
    if (Qt::LeftButton & e->buttons())
    {
    // left buttons is pressed
    }
    @



  • I encountered the same problem. Did anyone know what is the problem and solution?
    The problem actually is the subclass_QGraphicsScene::mouseMoveEvent() is not invoked button move around with left button down, but the mousePressEvent() and mouseRelease() working fine.
    Thanks much for any idea.



  • I encountered the same problem. Did anyone know what is the problem and solution?
    The problem actually is the subclass_QGraphicsScene::mouseMoveEvent() is not invoked button move around with left button down, but the mousePressEvent() and mouseRelease() working fine.
    Thanks much for any idea.


Log in to reply