Results 1 to 11 of 11

Thread: mouse tracking in QGraphicsItem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Posts
    38
    Thanks
    29
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default mouse tracking in QGraphicsItem

    First ,let me explain what problem I have countered.
    I use QGraphicsView Frame.I create a class Cordinate which inherits from QGraphicsItem.This class's main work is to draw a Cordinate System.
    Now I want to track mouse postion in this cordinate system. While I implement mouseMoveEvent(QGraphicsSceneMouseEvent * event), and
    mousePressEvent(QGraphicsSceneMouseEvent * event) in this Cordinate class. And here is my code :
    Qt Code:
    1. void Cordinate::mouseMoveEvent(QGraphicsSceneMouseEvent * event)
    2. {
    3. QGraphicsItem::mouseMoveEvent(event);
    4. float x = event->pos().x;
    5. qDebug() << "mouse move " << endl;
    6. }
    7. void Cordinate::mousePressEvent(QGraphicsSceneMouseEvent * event)
    8. {
    9. QGraphicsItem::mousePressEvent(event);
    10. QPointF point = event->pos();
    11. qDebug()<<"mouse press point is ("<< point.x() <<", "<<point.y()<<")"<<endl;
    12. }
    To copy to clipboard, switch view to plain text mode 
    And when run, the console print out the mouse press point ,but doesn't print out the mouse move?
    Why?Doesn's the item grab the mouse move event? And how I can work out this problem?
    Wish your help, please! Thank you very much!

    Oh, last and the most ,I have another class which is Cordinate class's child item!
    Last edited by wysota; 7th March 2009 at 12:26. Reason: missing [code] tags

Similar Threads

  1. mouse tracking on image
    By vermarajeev in forum Qt Programming
    Replies: 14
    Last Post: 12th May 2010, 13:06
  2. QGraphicsItem mouse events
    By zgulser in forum Qt Programming
    Replies: 13
    Last Post: 11th February 2009, 11:19
  3. Replies: 9
    Last Post: 22nd June 2008, 22:26
  4. Replies: 7
    Last Post: 8th September 2006, 16:19
  5. [QT3+XP] transparency and mouse tracking
    By incapacitant in forum Newbie
    Replies: 9
    Last Post: 17th February 2006, 18:49

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.