如何将 pyside QGraphicsScene 添加到 BoxLayout

how to add a pyside QGraphicsScene to a BoxLayout

我有一个 PySide2.QtWidgets.QVBoxLayout 和一个 PySide2.QtWidgets.QGraphicsScene,我想将 GraphicsScene 放在布局中。这是我的代码的一部分:

self.cn_graph = QtWidgets.QGraphicsScene()
[...]
self.ly_bottom = QtWidgets.QVBoxLayout()
[...]
self.ly_bottom.addWidget(self.cn_graph)

但我收到此错误:

TypeError: 'PySide2.QtWidgets.QBoxLayout.addWidget' called with wrong argument types:
  PySide2.QtWidgets.QBoxLayout.addWidget(QGraphicsScene)
Supported signatures:
  PySide2.QtWidgets.QBoxLayout.addWidget(PySide2.QtWidgets.QWidget, int = 0,         
  PySide2.QtCore.Qt.Alignment = Default(Qt.Alignment))
  PySide2.QtWidgets.QBoxLayout.addWidget(PySide2.QtWidgets.QWidget)

我不知道是否有可能在 boxlayout 中加入 graphicsscene 所以欢迎任何想法。

QGraphicsScene 不是一个小部件,它不是一个视觉元素,而是一个绘画处理程序,您应该使用 QGraphicsView:

self.cn_scene_graph = QtWidgets.QGraphicsScene()
self.cn_view_graph = QtWidgets.QGraphicsView(self.cn_scene_graph)
# ...
self.ly_bottom = QtWidgets.QVBoxLayout()
# ...
self.ly_bottom.addWidget(self.cn_view_graph)