1
votes

I am trying to display a QGraphicsView inside a QGraphicsWidget, but I can't seem to get it to work.

This is what I want to achieve, where the QGraphicsWidgets are all added to a QGraphicsScene, and each widget has their own QGraphicsScene and QGraphicsView. enter image description here The large box represents the main view, and the smaller boxes represent widgets, each with their own view and scenes.

My current implementation doesn't work, due to the following error:

TypeError: QGraphicsLinearLayout.addItem(QGraphicsLayoutItem): argument 1 has unexpected type 'QGraphicsView'

My implemetation in a subclass of the QGraphicsWidget:

self.scene = QtGui.QGraphicsScene(self)
self.view = QtGui.QGraphicsView(self.scene)
self.view.setRenderHint(QtGui.QPainter.Antialiasing)

self.setLayout(QtGui.QGraphicsLinearLayout(Qt.Vertical))
self.layout().addItem(self.view)

I've tried to implement this with a QGraphicsLayoutItem, but I couldn't find anywhere to stick the QGraphicsView in.

Any help would be appreciated.

1

1 Answers

3
votes

The function QGraphicsLinearLayout.addItem expects a QGraphicsWidget parameter and you are passing a normal QWidget (QGraphicsView).

You can use the class QGraphicsProxyWidget which is specially designed for wrapping QWidget into QGraphicsWidget.

I do not have Qt + Python on hands but I think it should look as follows:

proxy = parentView.addWidget(nestedView) # QWidget -> QGraphicsWidget
self.layout().addItem(proxy)