Results 1 to 3 of 3

Thread: mousemove event in QGraphics

  1. #1
    Join Date
    May 2012
    Posts
    16
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default mousemove event in QGraphics

    I'm trying to make the program do something while mouse moving in my qgraphics scene/view.but it only works for mousePress event. However it also works when I'm moving my mouse outside the scene/view.
    here is my code:

    void Main::mousePressEvent(QMouseEvent *e) {...}
    void Main::mouseMoveEvent(QMouseEvent *e) {...}

  2. #2
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mousemove event in QGraphics

    mouse move events only occur when a button is pressed by default, you need to setMouseTracking(true) on the view for the move events to generated in the first place, so that it can forward those to the scene.
    Alternatively, if you don't need the translation to scene coordinates, you could reimplement the mouseMoveEvent in the view directly rather than in your scene. But in this case, make sure you call the base class QGraphicsView::mouseMoveEvent in your implementation, so that hover events are properly generated for the items in your scene.

  3. The following user says thank you to pkj for this useful post:

    Dopt (5th July 2012)

  4. #3
    Join Date
    May 2012
    Posts
    16
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: mousemove event in QGraphics

    okay, thanks!

Similar Threads

  1. The Mystery of MouseMove Signals
    By tescrin in forum Qt Programming
    Replies: 2
    Last Post: 29th June 2012, 17:45
  2. Highlight PushButton on mouseMove
    By Shiva in forum Qt Programming
    Replies: 2
    Last Post: 15th October 2010, 13:38
  3. Problem in MouseMove Event
    By Gamalof in forum Qt Programming
    Replies: 4
    Last Post: 17th June 2008, 20:24
  4. mouseMove Event
    By fruzzo in forum Qt Programming
    Replies: 1
    Last Post: 3rd March 2008, 11:48
  5. Replies: 6
    Last Post: 3rd February 2006, 09:48

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.