Thursday, 15 August 2013

c++ - How to execute the mouseevent of qgraphicsitem only ? (ignoring the rest of mouseevent of qgraphicsview) -


I know how to pass the events of qgraphicsitem from qgraphicsview but the problem is after the mouse event of the item is executed , I have to execute the mouse event of the scene which is not desirable in my case. Therefore, the question is: "Is there a great way to know whether the mouseut is on an item or in an empty space?"

Edit: Task Code:

  Add # & lt; QtGui & gt; Class Custom View: Public QGraphicsView {protected: void mousePressEvent (QMouseEvent * event) {QGraphicsView :: mousePressEvent (event); QDebug () & lt; & Lt; "Custom view clicked."; }}; Class CustomItem: Public QGraphicsRectItem {protected: void mousePressEvent (QGraphicsSceneMouseEvent * event) {qDebug () & lt; & Lt; "Custom items were clicked on."; }}; Int main (int argc, char * argv []) {Q Application A (argc, argv); Custom item items; Item.setRect (20, 20, 60, 60); QGraphicsScene View (0, 0, 100, 100); Scene.addItem (& amp; item); Custom view view; View.setScene (& amp; View); View.show (); Back a.exec (); }   

Implementing the same concept in a Qigraphic view instead of the view

  #include & lt; QtGui & gt; Class Custom Sceeen: Public QGraphicsScene {Secure: Zero Mousepress Event (QGraphicsSceneMouseEvent * event) {if- (Event- (Event-> Scene ()) QGraphicsScene :: mousePressEvent ((Event)); Other qDebug () & lt; & Lt; "Custom view clicked."; }}; Class CustomItem: Public QGraphicsRectItem {protected: void mousePressEvent (QGraphicsSceneMouseEvent * event) {qDebug () & lt; & Lt; "Custom items were clicked on."; }}; Int main (int argc, char * argv []) {Q Application A (argc, argv); Custom item items; Item.setRect (20, 20, 60, 60); Custom scene; //scene().set scene.addItem (& amp; item); See QGraphicsView; View.setScene (& amp; View); View.show (); Back a.exec (); }    

You can not use a mouse resonator object or you can not use it :

  Zero Customview :: Mousepress Event (Cubiz Event * Event) {If (item-> pos ()) // Click on the item // Other // Click on the empty space. .}    

No comments:

Post a Comment