Results 1 to 3 of 3

Thread: How to get event of clicking out of a QGraphicsItem

  1. #1
    Join Date
    Jul 2011
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to get event of clicking out of a QGraphicsItem

    hello,
    i have a class implemented from QGraphicsItem, called Node.

    i have a rectangle shaped "Node" and i can do something when user clicked on it

    i use mousePress and mouseRelease events.

    but i want to be notified when user clicked "out of" the rectangle shape.

    i tried to implement these functions:

    Qt Code:
    1. void Node::focusInEvent ( QFocusEvent * event){
    2. cout<<"in"<<endl;
    3. update();
    4.  
    5. QGraphicsItem::focusInEvent(event);
    6. }
    7. void Node::focusOutEvent ( QFocusEvent * event ){
    8. cout<<"out"<<endl;
    9. update();
    10. QGraphicsItem::focusOutEvent(event);
    11.  
    12. }
    13. void Node::hoverEnterEvent(QGraphicsSceneHoverEvent *event){
    14. cout<<"out"<<endl;
    15. }
    To copy to clipboard, switch view to plain text mode 

    these do not reacts if i click in or out of rectangle.
    should i set a logic on my own for example getting the mouse position and control if it is out of rectangle?
    or is there a built in method?
    thanks for any idea.


    Added after 39 minutes:


    or how can a "Node" object know if other Node object is clicked?

    also i wonder, googled but could not found that when does focusinevent and focusoutevent triggered?
    Last edited by tuxit; 29th July 2011 at 14:18.

  2. #2
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: How to get event of clicking out of a QGraphicsItem

    If you want to click out of object shape and be notified, you need to capture the event in GraphicsScene mousePressEvent.
    or how can a "Node" object know if other Node object is clicked?
    If Node inherits QGraphicsObject, it can emit a signal connected to other Node objects slots. If not, then you can capture the click in Scene's mousePressEvent, check if node will be under cursor (so it will get clicked) and notify other Nodes on scene manually.

  3. #3
    Join Date
    Jul 2011
    Posts
    22
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to get event of clicking out of a QGraphicsItem

    thanks for the reply
    i achieved to run focusInEvent and focusOutEvent by seting flags by
    Qt Code:
    1. setFlags(ItemIsSelectable|ItemIsMovable|ItemIsFocusable);
    To copy to clipboard, switch view to plain text mode 
    i have asked about to be notified on click on other object because i could not get worked focusOut. now it s ok.
    thanks

Similar Threads

  1. QGraphicsItem hover event
    By xgoan in forum Qt Programming
    Replies: 6
    Last Post: 4th January 2016, 15:08
  2. QGraphicsItem's hover event problem
    By lni in forum Qt Programming
    Replies: 1
    Last Post: 29th July 2011, 05:51
  3. Replies: 0
    Last Post: 4th October 2010, 21:53
  4. mouseWheel event not going to QGraphicsItem
    By spacedman in forum Qt Programming
    Replies: 0
    Last Post: 17th March 2009, 20:03
  5. QGraphicsItem event->ignore()
    By fres in forum Qt Programming
    Replies: 1
    Last Post: 25th October 2007, 14: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.