trouble using pyqtgraph widget in custom ui with PySide instead of PyQt4

1,852 views
Skip to first unread message

Jason Frazier

unread,
Mar 25, 2014, 3:26:22 PM3/25/14
to pyqt...@googlegroups.com
I made a simple ui file in QT designer that holds a graphics view widget, promoted to a pyqtgraph PlotWidget, as per instructions at the pyqtgraph site.
I converted this .ui file to .py file using pyuic4.
I wrote the code below to launch the interface with the embedded pyqtgraph widget.

from PyQt4 import QtGui
import pyqtgraph as pg

from TestUi import Ui_MainWindow

class dlgTest(QtGui.QMainWindow):
    def __init__(self, parent=None):
        QtGui.QMainWindow.__init__(self,parent)
        self.ui=Ui_MainWindow()
        self.ui.setupUi(self)           
        wp=self.ui.wPlot    #This is the pyqtgraph widget.
            
if __name__ == "__main__":
    app=QtGui.QApplication([])
    myapp=dlgTest()
    myapp.show()
    app.exec_()

This seems to work fine.  

My problem arises from trying to do the exact same thing using PySide instead of PyQt4.  

In an attempt to do this I changed first line of code above to read 'from PySide import QtGui'.  
Then I used pySide-uic to create TestUi.py.

This program now fails during initialization of the graphics view widget, seemingly because thi __init__ function for the widget expected a Qwidget as input, and instead got an object of type pyside.qtgui.gwidget.

What am I missing here?  I realize it's probably a simple question, but would really appreciate it if somebody could point me in the right direction.

Thanks!

J...

ps - I can get a similar error by trying to run the sample code at http://www.pyqtgraph.org/documentation/qtcrashcourse.html (which says it is PySide compatible) after changing the first line to import QtGui from PySide instead of PyQt4.

full error for PySide version of the above code is below:

Traceback (most recent call last):
  File "D:\Python Projects\Learn pyqtgraph\main.py", line 22, in <module>
    myapp=dlgTest()
  File "D:\Python Projects\Learn pyqtgraph\main.py", line 17, in __init__
    self.ui.setupUi(self)           
  File "D:\Python Projects\Learn pyqtgraph\\TestUi.py", line 21, in setupUi
    self.wPlot = PlotWidget(self.centralwidget)
  File "C:\Apps\WinPython-32bit-2.7.5.3\python-2.7.5\lib\site-packages\pyqtgraph\widgets\PlotWidget.py", line 48, in __init__
    GraphicsView.__init__(self, parent, background=background)
  File "C:\Apps\WinPython-32bit-2.7.5.3\python-2.7.5\lib\site-packages\pyqtgraph\widgets\GraphicsView.py", line 73, in __init__
    QtGui.QGraphicsView.__init__(self, parent)
TypeError: arguments did not match any overloaded call:
  QGraphicsView(QWidget parent=None): argument 1 has unexpected type 'PySide.QtGui.QWidget'
  QGraphicsView(QGraphicsScene, QWidget parent=None): argument 1 has unexpected type 'PySide.QtGui.QWidget'



Luke Campagnola

unread,
Mar 25, 2014, 5:45:36 PM3/25/14
to pyqt...@googlegroups.com
On Tue, Mar 25, 2014 at 3:26 PM, Jason Frazier <cjfr...@gmail.com> wrote:
My problem arises from trying to do the exact same thing using PySide instead of PyQt4.  

In an attempt to do this I changed first line of code above to read 'from PySide import QtGui'.  
Then I used pySide-uic to create TestUi.py.

This program now fails during initialization of the graphics view widget, seemingly because thi __init__ function for the widget expected a Qwidget as input, and instead got an object of type pyside.qtgui.gwidget.

It sounds like pyqtgraph is importing PyQt instead of PySide.  You can check this by running `pg.systemInfo()`.
I'm not sure why, though--when I run the crash course with PySide, it works as expected.
The rules it uses for making this decision are:
  1. If PyQt is already imported, use that
  2. If PySide is already imported, use that
  3. If PyQt is importable, use that
  4. If PySide is importable, use that

So if you already have PyQt imported elsewhere in your application, pyqtgraph will choose that over PySide. 
Since I can't reproduce this at the moment, you might try poking around in pyqtgraph/Qt.py. The very first block of code around line 17 is what decides whether to import PyQt/PySide; it would be helpful to know what is happening in there.


Luke

 
Message has been deleted

Jason Frazier

unread,
Mar 25, 2014, 8:41:27 PM3/25/14
to pyqt...@googlegroups.com
Argh.. yes, pyqtgraph was importing pyqt instead of pyside (confirmed with pg.systemInfo()).  The reason (duh) was that I was running the code in a 'new dedicated python interpreter' as defined by WinPython, which means in an environment where guiqwt had already been imported. That's why the import PySide statement in my code wasn't enough to get pyqtgraph to use PySide.  The quickest solution was to change the run settings for my program in WinPython to run in an 'external system terminal'.  Now systemInfo() confirms pyqtgraph using pySide qt bindings, and code works as expected.  Thanks very much for the quick and insightful help.  I'm very impressed with pyqtgraph so far, and think I will give it a go over PyQwt for our upcoming project!

J...


Reply all
Reply to author
Forward
0 new messages