2016-09-21 30 views
1

我只是從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 

回答

0

您可以分享ui_pumptest.py文件源嗎?否則很難說出你的意圖是什麼。如果沒有,至少要詳細說明你在QtDesigner中用於放置QGraphicsView升級過程的結構(假設你遵循了http://www.pyqtgraph.org/documentation/how_to_use.html#embedding-widgets-inside-pyqt-applications)。

pg.plot創建它自己的plotwindow-> plotwidget結構,所以這就是爲什麼你調用它時會得到一個單獨的窗口。你調用的項目應該是在你的Qt UI文件中提升的容器對象名稱。

相關問題