Error Embedding Pyqtgraph into PyQt4 GraphicsView
<p>I am attempting to embed a pyqtgraph into a PyQt4 GraphicsView widget. I am getting an error with the following code:. What am I doing wrong?</p>

<pre><code>#imports
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, pg):
    vb = pg.ViewBox() 

    def __init__(self):        
        super(self.__class__, self).__init__()        
        self.setupUi(self)  # This is defined in ui_pumptest.py file automatically        
        self.graphicsView.setCentralItem(self.vb)   #set central item to be graph


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
</code></pre>

<p>The error is:</p>

<pre><code>QWidget: Must construct a QApplication before a QPaintDevice
</code></pre>

<p>The two things that need to be fixed with this code:
(1)
Remove pg from base class list, you don't inherit from the whole pyqtgraph library:</p>

<pre><code>class Gui(QtGui.QMainWindow, ui_test.Ui_MainWindow, pg):
</code></pre>

<p>to</p>

<pre><code>class Gui(QtGui.QMainWindow, ui_test.Ui_MainWindow):
</code></pre>

<p>(2)
Construct the viewbox inside the <strong>init</strong>:</p>

<pre><code>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.vb = pg.ViewBox() 
        self.graphicsView.setCentralItem(self.vb)   #set central item to be graph
</code></pre>

python pyqt4 qgraphicsview pyqtgraph