#include <QtGui>
{
public:
{}
void deleteScene()
{
setScene(0);
sc->deleteLater();
//ONE BUG: The view is not updated when scene is set to 0
}
};
{
public:
{
view = v;
}
{
scene()->removeItem(this);
view->deleteScene();
}
View * view;
};
int main(int argc, char *argv[])
{
View *v = new View(scene);
Item
*it
= new Item
(QRectF(10,
10,
40,
30),scene,v
);
v->show();
return app.exec();
}
#include <QtGui>
class View : public QGraphicsView
{
public:
View(QGraphicsScene *sc) : QGraphicsView(sc)
{}
void deleteScene()
{
QGraphicsScene *sc = scene();
setScene(0);
sc->deleteLater();
//ONE BUG: The view is not updated when scene is set to 0
}
};
class Item : public QGraphicsEllipseItem
{
public:
Item(QRectF rect, QGraphicsScene *scene,View *v) : QGraphicsEllipseItem(rect,0,scene)
{
view = v;
}
void mousePressEvent(QGraphicsSceneMouseEvent * event)
{
scene()->removeItem(this);
view->deleteScene();
}
View * view;
};
int main(int argc, char *argv[])
{
QApplication app(argc,argv);
QGraphicsScene *scene = new QGraphicsScene(0,0,800,600);
View *v = new View(scene);
Item *it = new Item(QRectF(10,10,40,30),scene,v);
v->show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks