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
){
//Create a new scene
myScene->setSceneRect(0, 0, 300.0, 300.0 );
//Creates items in scene myScene
populateScene(myScene);
myView
->setRenderHints
(QPainter::Antialiasing);
myLayout->addWidget(myView);
setLayout(myLayout);
}
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);
}
To copy to clipboard, switch view to plain text mode
newScene:
void myGraphicsWidget::newScene(void)
{
//Delete previous scene
delete myScene;
//Create a new scene
//Creates items in scene myScene
populateScene(myScene);
//Code here to update the widget/view???? <-- Need code here
}
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
}
To copy to clipboard, switch view to plain text mode
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?
Bookmarks