Results 1 to 6 of 6

Thread: How to handle QGraphicsItem mouse events in QGraphicsView

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    24
    Thanks
    5
    Qt products
    Qt4

    Default How to handle QGraphicsItem mouse events in QGraphicsView

    hi all,
    I wrote some objects derived from QGraphicsView and QGraphicsItem, and I simulate a mouse click event in my QGraphicsItem just like this
    Qt Code:
    1. void QMyItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
    2. {
    3. // if(e->buttons() == Qt::LeftButton)
    4. // SetButtonState(NORMAL);
    5.  
    6. QGraphicsPixmapItem::mousePressEvent(event);
    7.  
    8. setSelected(false); // i don't need the focus
    9.  
    10. QPointF lastpt = event->lastPos();
    11. QRectF bRect = boundingRect ();
    12.  
    13. if(bRect.contains(lastpt))
    14. ; // ??? It's a click event.
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

    My question is, how can i track the mouse 'click' event in my QGraphicsView? in other words, i need to integrate these mouse events in QGraphicsView and find which item activate it,
    Qt Code:
    1. void QMyGraphicsView::Command( param)
    2. {
    3. switch(param)
    4. {
    5. case ?? : ...
    6. case ?? : ...
    7. }
    8. ...
    9. }
    To copy to clipboard, switch view to plain text mode 

    or is there a better place to dispose other than QGraphicsView?

    thanks for any advice.
    Last edited by HiJack; 27th April 2010 at 07:24.

Similar Threads

  1. Handle Drag & Drop Events with QGraphicsItem [SOLVED]
    By guilugi in forum Qt Programming
    Replies: 2
    Last Post: 13th July 2010, 18:05
  2. QGraphicsItem no mouse events called
    By munna in forum Qt Programming
    Replies: 11
    Last Post: 9th December 2009, 14:43
  3. mouse events handling with QGraphicsItem
    By trallallero in forum Qt Programming
    Replies: 3
    Last Post: 21st October 2009, 14:15
  4. QGraphicsItem mouse events
    By zgulser in forum Qt Programming
    Replies: 13
    Last Post: 11th February 2009, 11:19
  5. QPushButton:: Handle right mouse button events. Easyway?
    By Harvey West in forum Qt Programming
    Replies: 6
    Last Post: 28th February 2007, 16:56

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.