Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    [solved] mouseMoveEvent doesn't respond...

    General and Desktop
    2
    4
    8463
    Loading More Posts
    • 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.
    • T
      ThaRez last edited by

      Hello
      I have a GraphicsViewItem for which I've implemented the mouse doubleclick & mousemove event functions:

      @protected:

      void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);
      void mouseMoveEvent( QGraphicsSceneMouseEvent* );
      

      @

      this is what they look like atm:

      @void clickItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
      {
      qDebug("double click!") ;

      }

      void clickItem::mouseMoveEvent( QGraphicsSceneMouseEvent* event )
      {
      qDebug("move");

      }@

      When I attach the item to a scene and display it, the double click function reacts as it should, but the move event function is dead, that is nothing happens... What am I missing?
      Thanks
      Richard

      1 Reply Last reply Reply Quote 0
      • A
        andre last edited by

        A mouse move is only fired if

        • you have mouse button down, or
        • you have enabled mouse tracking.

        Otherwise, you would drown the system in events that are not needed.

        To prevent problems later on, you should always(TM) call the base class event if you reimplement event handlers (or almost all virtual methods, for that matter).

        1 Reply Last reply Reply Quote 0
        • T
          ThaRez last edited by

          Hello
          What do you mean by calling the base class event? How to I do this? I just noticed it started working when I implemented the

          @virtual void mousePressEvent (QGraphicsSceneMouseEvent *event);@

          as well. It doesn't have to do anything, just be defined... Any ideas why? Another related problem I have is the now when I draw the items and try to select them, they're selectable only in the upper left corner (from where they're drawn) though both

          @QRectF boundingRect() const;
          QPainterPath shape() const;@

          have been defined to return the whole area... The interesting thing is, that after moving the item (grabbing it from the upper corner) it can be selected from anywhere inside the object (as it should be). Apparently this procedure updates some boundary redraw function, how can I do this manually when the object is drawn?
          Thank you!
          Best regards
          Richard

          1 Reply Last reply Reply Quote 0
          • A
            andre last edited by

            What I mean is, that you need to do this in your implementation:

            @
            void clickItem::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event)
            {
            qDebug("double click!") ;
            QGraphicsItem::mouseDoubleClickEvent(event); //assuming that QGraphicsItem is the base class for clickItem
            }
            @

            You do this for all eventhandlers. Depending on your specific use case, you can call it at the beginning, in the middle or at the end of your implementation, but you almost always will want to be making that call.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post