我只是從pyqtgraph開始。我有一個graphicsView小部件,我根據文檔使用QT設計器進行推廣。我想嘗試一個情節,看看它是否有效。當我嘗試pg.plot(x,y)
時,程序在一個單獨的窗口而不是在graphicsView小部件中創建了一個圖。我使用的是Windows 10,PyQt4和Python 2.7。我究竟做錯了什麼?如何在QT Designer中創建的PyQt4小部件上使用pyqtgraph繪製一個圖表?
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