The QGraphicsView has no directly connection to the QGraphicsItem objects inside of the scene. Its only purpose is to visualize a slice of your scene in a viewport, and transmit user interactions to the scene. There are no layouts, however layouts were added to be used with QGraphicsWidget (but that is a special needs case). Regardless, this is simply related to the translation of the view, as opposed to the position of the items in the scene (completely unrelated to each other)
What you will most likely need to do, is subclass QGraphicsView, and re-implement resizeEvent in your view: http://qt-project.org/doc/qt-4.8/qgraphicsview.html#resizeEvent
In the resizeEvent, you would translate the view by an amount based on the resize: http://qt-project.org/doc/qt-4.8/qgraphicsview.html#translate
Essentially, you are creating your own layout manager functionality within your custom QGraphicsView.
Update
I realize what you mean, that when the sceneRect is larger than the QGraphicsView, it will use scrollbars and not keep your view centered on resize. Ideally, if you are creating the type of graphics scene where the content doesn't need to scroll, you should leave the sceneRect default, or set it to the size of the viewport.
Otherwise, here is a really basic example of how you would use the resizeEvent. This is in PyQt but I am sure you can translate:
class Dialog(QtGui.QDialog):
def __init__(self):
super(Dialog, self).__init__()
self.resize(640,480)
layout = QtGui.QVBoxLayout(self)
self.scene = QtGui.QGraphicsScene(self)
self.scene.setSceneRect(-500,-500,1000,1000)
self.view = GraphicsView(self)
self.view.setScene(self.scene)
layout.addWidget(self.view)
text = self.scene.addText("Foo")
self.view.updateCenter()
class GraphicsView(QtGui.QGraphicsView):
def __init__(self, parent=None):
super(GraphicsView, self).__init__(parent)
self._center = None
def resizeEvent(self, event):
super(GraphicsView, self).resizeEvent(event)
if self._center:
self.centerOn(self._center)
def updateCenter(self):
center = self.geometry().center()
self._center = self.mapToScene(center)
It saves the scene point you are interested in when you call updateCenter()
. Then, every time your view resizes, it will center back to that scene point.
Update 2: After your picture posts and updates
If you really need this kind of normal QWidget behavior in a QGraphicsScene, with layouts, then you should be looking at QGraphicsWidgets, which do support layouts. Then you can make one large root "canvas" widget, and make everything else a child of that, inside of layouts. Then you only need to worry about keeping the root widget sized properly. You would then be able to use the same example above to manage the size and position of your root widget.
Refer to this question for more details since its the same situation of someone wanting to integrate a QGraphicsItem into layouts:
QGraphicsWidget vs. QGraphicsLayoutItem