dohzer
15th August 2010, 06:36
I've got a widget with a QGraphicsView and a QGraphicsScene, shown below.
I want to delete all items from the scene and create new ones, so I'm trying to delete the scene and create a new one.
myGraphicsWidget Constructor:
myGraphicsWidget::myGraphicsWidget(QWidget *parent)
: QWidget(parent)
{
//Create a new scene
myScene = new QGraphicsScene(this);
myScene->setSceneRect(0, 0, 300.0, 300.0 );
//Creates items in scene myScene
populateScene(myScene);
myView = new QGraphicsView(myScene);
myView->setRenderHints(QPainter::Antialiasing);
QVBoxLayout *myLayout = new QVBoxLayout;
myLayout->addWidget(myView);
setLayout(myLayout);
}
newScene:
void myGraphicsWidget::newScene(void)
{
//Delete previous scene
delete myScene;
//Create a new scene
myScene = new QGraphicsScene(this);
//Creates items in scene myScene
populateScene(myScene);
//Code here to update the widget/view???? <-- Need code here
}
When I try to run newScene(), I get a blank Widget.
Is there some code I need to insert at the end of newScene() to get it to update in the QGraphicsView and widget, or is this technique of deleting, creating and repopulating the scene not going to work?
Should I be deleting the individual items from the scene instead of deleting the whole scene?
I want to delete all items from the scene and create new ones, so I'm trying to delete the scene and create a new one.
myGraphicsWidget Constructor:
myGraphicsWidget::myGraphicsWidget(QWidget *parent)
: QWidget(parent)
{
//Create a new scene
myScene = new QGraphicsScene(this);
myScene->setSceneRect(0, 0, 300.0, 300.0 );
//Creates items in scene myScene
populateScene(myScene);
myView = new QGraphicsView(myScene);
myView->setRenderHints(QPainter::Antialiasing);
QVBoxLayout *myLayout = new QVBoxLayout;
myLayout->addWidget(myView);
setLayout(myLayout);
}
newScene:
void myGraphicsWidget::newScene(void)
{
//Delete previous scene
delete myScene;
//Create a new scene
myScene = new QGraphicsScene(this);
//Creates items in scene myScene
populateScene(myScene);
//Code here to update the widget/view???? <-- Need code here
}
When I try to run newScene(), I get a blank Widget.
Is there some code I need to insert at the end of newScene() to get it to update in the QGraphicsView and widget, or is this technique of deleting, creating and repopulating the scene not going to work?
Should I be deleting the individual items from the scene instead of deleting the whole scene?