Hi all,

There is two GraphicObjects. Both have mousepressevent and also needed to be seen in a QGraphicsScene. The first GraphicObjects(let say A), when user clicks on it the second GraphicObjects(let say B) will be painted on the QGraphicScene while A still remain in the scene. But when user clicks on B the object A will be deleted together with B after being clicked. I use SIGNAL & SLOT to implement this which can only work for 1 pair. It became chaotic when there is plenty of object A in the scene. Please help me. I write down a pseudo code below.

Qt Code:
  1. class A
  2. {
  3. paint()//paints the object
  4. mousePressEvent
  5. {
  6. emit drawBtn//emit signal
  7. }
  8. }
  9.  
  10. class B
  11. {
  12. mousePressEvent
  13. {
  14. emit DestroyA
  15. emit DestroySelf
  16. }
  17. }
  18.  
  19. class Widget
  20. {
  21. Widget()
  22. {
  23. scene = new QGraphicsScene
  24. view = new QGraphicsView
  25. createA();//this one only work once.
  26.  
  27. }
  28.  
  29. void createA()
  30. {
  31. //create classA and add to the scene
  32. connect(A, SIGNAL(drawBtn()),this,SLOT(drawTheBtn())
  33. }
  34. void drawTheBtn()
  35. {
  36. //create classB and add to the scene
  37. connect(B, SIGNAL(destroyA()),A,SLOT(deleteLater())
  38. connect(B, SIGNAL(destroySelf(),B,SLOT(deleteLater())
  39. }
  40.  
  41. }
To copy to clipboard, switch view to plain text mode