Results 1 to 7 of 7

Thread: mouseMoveEvent in QGraphicsItem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Posts
    134
    Thanks
    10
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default mouseMoveEvent in QGraphicsItem

    Dear All,
    I have re-implemented mouseMoveEvent(QGraphicsSceneMouseEvent *event) in my class which is derived from QGraphicsItem. When i draw an item on scene and move the mouse cursor inside the item, mouseMoveEvent() will not trigger. It will only trigger when i click on the item and move the mouse inside the item (i.e leftclick + move). I have set the setAcceptHoverEvents(true). But still mouseMoveEvent() event doesn't trigger. Can anyone tell how can i resolve this problem such that, mouse move on item trigger mouseMoveEvent(). Following is my code

    Qt Code:
    1. CMyItem::CMyItem(QPointF center, QSizeF size)
    2. {
    3. m_Rectangle.setSize(size);
    4. m_Rectangle.moveTopLeft(center);
    5. setZValue(((int)m_Rectangle.top() + (int)m_Rectangle.left())% 2);
    6.  
    7. setFlags(ItemIsSelectable | ItemIsMovable);
    8. setAcceptHoverEvents(true);
    9. }
    10.  
    11. CMyItem::~CMyItem()
    12. {
    13.  
    14. }
    15.  
    16. QRectF CMyItem::boundingRect() const
    17. {
    18. return QRectF(0, 0, 200, 100);
    19. }
    20.  
    21. QPainterPath CMyItem::shape() const
    22. {
    23. path.addRect(0, 0, 200, 100);
    24. return path;
    25. }
    26.  
    27. void CMyItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    28. {
    29. Q_UNUSED(widget);
    30. //QBrush brush(
    31. QPen pen;
    32. pen.setColor(Qt::black);
    33. painter->setPen(pen);
    34. painter->drawRect(m_Rectangle);
    35. }
    36.  
    37. void CMyItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
    38. {
    39. QGraphicsItem::mousePressEvent(event);
    40. update();
    41. event->accept();
    42.  
    43. }
    44.  
    45. void CMyItem::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
    46. {
    47. QGraphicsItem::mouseMoveEvent(event);
    48. }
    49.  
    50. void CMyItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
    51. {
    52. QGraphicsItem::mouseReleaseEvent(event);
    53. update();
    54. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 6th July 2009 at 12:31. Reason: missing [code] tags

Similar Threads

  1. Replies: 5
    Last Post: 31st December 2010, 11:49
  2. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 10:31
  3. Replies: 1
    Last Post: 25th February 2009, 00:34
  4. Snap-to grid on QGraphicsItem
    By hardgeus in forum Qt Programming
    Replies: 9
    Last Post: 28th April 2008, 16:22
  5. Replies: 6
    Last Post: 30th April 2007, 23:59

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.