I have a QGraphicsView inside a Horizontal Layout. The QGraphicsScene contained in the QGraphics scene is pretty large (thousands of pixels), so scroll bars show up by default to allow me to scroll through the view.
Every time I update the scene inside the graphics scene, I delete the old scene, make a new one, populate it with objects, and call view->setScene(scene). When I do this, however, the scroll bars default to the top left corner of the QGraphicsView, instead of staying where they were at.
I tried saving the QGraphicsScene::sceneRect before destroying the scene, then doing a setSceneRect() afterwards to restore it, but that doesn't work since that only affects the scene itself, not the QGraphicsView that's displaying it. I also tried to do view->verticalScrollBar()->setValue(), but that doesn't appear to affect the scroll bars at all.
How can I access the scroll bars that are created for me by default, and set them to a value that was stored earlier?
Fixed by not deleting previous scene until after the new one is set.
e.g.
QGraphicsScene *previousScene = scene;
scene = new QGraphicsScene(0, 0, levelPlist.value("level_width").toInt(), levelPlist.value("level_height").toInt());
// config scene
QGraphicsView *view = ui->graphicsView;
view->setScene(scene);
delete previousScene;