Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with QGraphicsScene mouse move event
Qt 6.11 is out! See what's new in the release blog

Problem with QGraphicsScene mouse move event

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 6.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nesbit
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      "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
      }
      @

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved