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.
class A
{
paint()//paints the object
mousePressEvent
{
emit drawBtn//emit signal
}
}
class B
{
mousePressEvent
{
emit DestroyA
emit DestroySelf
}
}
class Widget
{
Widget()
{
createA();//this one only work once.
}
void createA()
{
//create classA and add to the scene
connect(A, SIGNAL(drawBtn()),this,SLOT(drawTheBtn())
}
void drawTheBtn()
{
//create classB and add to the scene
connect(B, SIGNAL(destroyA()),A,SLOT(deleteLater())
connect(B, SIGNAL(destroySelf(),B,SLOT(deleteLater())
}
}
class A
{
paint()//paints the object
mousePressEvent
{
emit drawBtn//emit signal
}
}
class B
{
mousePressEvent
{
emit DestroyA
emit DestroySelf
}
}
class Widget
{
Widget()
{
scene = new QGraphicsScene
view = new QGraphicsView
createA();//this one only work once.
}
void createA()
{
//create classA and add to the scene
connect(A, SIGNAL(drawBtn()),this,SLOT(drawTheBtn())
}
void drawTheBtn()
{
//create classB and add to the scene
connect(B, SIGNAL(destroyA()),A,SLOT(deleteLater())
connect(B, SIGNAL(destroySelf(),B,SLOT(deleteLater())
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks