Search code examples
python-3.xpyqt4pyqtgraphxubuntu

add pyqtgraph (plot) into QApplication


hy,

soooo, i created the MainWindow.ui file with the QTDesigner. Then i import this gui with following command into my .py file:

form_class = uic.loadUiType("ess_project.ui")[0]  

What is the difference if i compile this .ui file with pyuic4 ? (every time i compiled my .ui file i got following error:

RuntimeError: the sip module implements API v11.0 to v11.1 but the PyQt4.QtCore module requires API v10.1

The MainWindow create the first window, where all buttons etc. are placed.

class MainWindow(QtGui.QMainWindow, form_class):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self, parent)
        PlotWindow.__init__(self)
        self.setupUi(self)
        self.pb_send.clicked.connect(self.pb_send_clicked)
        self.pb_open.clicked.connect(self.pb_open_clicked)
        self.pb_exit.clicked.connect(self.pb_exit_clicked)
        self.comboBox.currentIndexChanged.connect(self.combo_box_changed)

furthermore i have a second class named "PlotWindow". This class looks like this:

class PlotWindow(QtGui.QMainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        self.w = QtGui.QMainWindow()
        self.cw = pg.GraphicsLayoutWidget()
        self.w.show()
        self.w.resize(900,600)
        self.w.setCentralWidget(self.cw)
        self.w.setWindowTitle('pyqtgraph: G-CODE')
        self.p = self.cw.addPlot(row=0, col=0)

now as you can see, the PloWindow - class create a second Window.

How can i implement the pg.GraphicsLayoutWidget() into the MainWindow - class ??

not sure if this can help you ?!? :

def main():
    app = QtGui.QApplication([])
    myWindow = MainWindow(None)
    myWindow.show()
    app.exec_()

if __name__ == '__main__':
    main()

I am using python3 !!! feel FREE to comment :) thanks !


Solution

  • To place any pyqtgraph widgets inside your application, you add a placeholder widget and "promote" it to the pg class that you want. See: http://www.pyqtgraph.org/documentation/how_to_use.html#embedding-widgets-inside-pyqt-applications