如何在QT设计器中创建的PyQt4小部件上使用pyqtgraph绘制绘图?

2024-04-26 08:06:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我只是从pyqtgraph开始。我有一个graphicsView小部件,我根据文档使用QT designer进行了升级。我想试一下情节,看看是否有效。当我尝试pg.plot(x,y)时,程序在一个单独的窗口中而不是在graphicsView小部件中创建了一个绘图。我使用的是Windows10、PyQt4和Python2.7。我做错什么了?在

from PyQt4 import QtGui
from PyQt4 import QtCore
import ui_test  #Gui File
import sys
import pyqtgraph as pg


class Gui(QtGui.QMainWindow, ui_test.Ui_MainWindow):


    def __init__(self):        
        super(self.__class__, self).__init__()        
        self.setupUi(self)  # This is defined in ui_pumptest.py file automatically   
        self.plot()

    def plot(self):       
        vb = pg.ViewBox()
        self.graphicsView.setCentralItem(vb)
def main():
    app = QtGui.QApplication(sys.argv)  # A new instance of QApplication
    form = Gui()  # We set the form to be our ExampleApp (design)
    form.show()  # Show the form
    app.exec_()  # and execute the. app

if __name__ == '__main__':  # if we're running file directly and not importing it
    main()  # run the main function

Tags: theimportselfformappuiplotmain
1条回答
网友
1楼 · 发布于 2024-04-26 08:06:18

你能分享用户界面吗_泵试验文件来源?否则很难判断你的意图是什么。如果没有,至少详细说明在QtDesigner的QGraphicsView升级过程中使用了什么构造(假设您遵循了http://www.pyqtgraph.org/documentation/how_to_use.html#embedding-widgets-inside-pyqt-applications)。在

在pg.绘图创建它自己的plotwindow->;plotwidget结构,因此如果调用该结构,则会获得一个单独的窗口。调用plot的项应该是在qtui文件中升级的容器对象名。在

相关问题 更多 >