【问题标题】:how to add a scene to a previously defined QGraphicsView如何将场景添加到先前定义的 QGraphicsView
【发布时间】:2021-08-24 07:38:33
【问题描述】:

我有一个预定义的 GUI,它作为 .ui 文件加载:

def __init__(self):
    # Initialise main program with GUI
    super(MainWindow, self).__init__()
    uic.loadUi('fg_control_gui_2.ui', self)

在该 ui 文件中,我定义了一个 QGraphicsView,它在 .py 版本的 GUI 中如下所示:

    self.ch1_oszi_view = QtWidgets.QGraphicsView(self.centralwidget)
    self.ch1_oszi_view.setGeometry(QtCore.QRect(10, 450, 361, 261))
    self.ch1_oszi_view.setObjectName("ch1_oszi_view")

现在我想添加一个 QGraphicsScene 作为画布,这样我就可以在我的 GUI 中显示一个应该像这样完成的绘图:

scene = QtWidgets.QGraphicsScene()
view = QtWidgets.QGraphicsView(scene)

我现在的问题是,我怎样才能将场景交给之前定义的 QGraphicsView,就像我在上一个示例的第二行代码中所做的那样?

【问题讨论】:

    标签: python pyqt qgraphicsview qgraphicsscene


    【解决方案1】:

    你必须使用QGraphicsViewsetScene()方法:

    scene = QtWidgets.QGraphicsScene()
    self.ch1_oszi_view.setScene(scene)
    

    【讨论】:

    • @darmstadtbeste 请阅读How to Ask 并查看tour
    • 我这样做了,我的问题有什么问题?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-09-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    • 2021-11-16
    • 2021-12-09
    • 2011-10-17
    相关资源
    最近更新 更多