4

I'd like to implement a PyQtGraph PlotWidget into a PySide2 application. With PyQt5 everything works. With PySide2 I get the Error shown at the bottom. I already found out, that there's some work in progress, but also it seems that a few people managed to get this working. However, I was not able yet. I am using Pyqtgraph 0.10 and not the developer branch. Shall I change? What do I need to do?

from PySide2.QtWidgets import QApplication, QMainWindow, QGraphicsView, QVBoxLayout, QWidget
import sys
import pyqtgraph as pg


class WdgPlot(QWidget):
    def __init__(self, parent=None):
        super(WdgPlot, self).__init__(parent)
        self.layout = QVBoxLayout(self)

        self.pw = pg.PlotWidget(self)
        self.pw.plot([1,2,3,4])
        self.pw.show()
        self.layout.addWidget(self.pw)
        self.setLayout(self.layout)
if __name__ == '__main__':

    app = QApplication(sys.argv)
    w = WdgPlot()
    w.show()
    sys.exit(app.exec_())

Error:

 QtGui.QGraphicsView.__init__(self, parent)
TypeError: arguments did not match any overloaded call:
  QGraphicsView(parent: QWidget = None): argument 1 has unexpected type 'WdgPlot'
  QGraphicsView(QGraphicsScene, parent: QWidget = None): argument 1 has unexpected type 'WdgPlot'
Traceback (most recent call last):
eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Sebus
  • 55
  • 1
  • 7

2 Answers2

6

In the stable branch of pyqtgraph even PySide2 is not supported, so it is importing QtGui.QGraphicsView that must belong to PyQt4 or PySide since in PyQt5 and PySide2 QGraphicsView belongs to the submodule QtWidgets and not to QtGui.

In the develop branch, PySide2 support is being implemented, so if you want to use PySide2 you will have to install it manually using the following commands (you must first uninstall your installed pyqtgraph):

git clone -b develop git@github.com:pyqtgraph/pyqtgraph.git
sudo python setup.py install

Then you can use:

from PySide2 import QtWidgets
import pyqtgraph as pg


class WdgPlot(QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(WdgPlot, self).__init__(parent)
        layout = QtWidgets.QVBoxLayout(self)

        pw = pg.PlotWidget()
        pw.plot([1,2,3,4])
        layout.addWidget(pw)


if __name__ == '__main__':
    import sys
    app = QtWidgets.QApplication(sys.argv)
    w = WdgPlot()
    w.show()
    sys.exit(app.exec_())

enter image description here

More information in:

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Thank you very much. This works, but have an additional problem with a broken PySide2 install. – Sebus Sep 28 '18 at 09:34
  • 2
    Thanks! It may be of interest : I am using `pyenv` to manage my python environments, and instead of cloning / building the setup "by hand", I used the solution proposed on [pyqtraph's github page](https://github.com/pyqtgraph/pyqtgraph) so that the installation is local to my env. I used the following command `pip install git+https://github.com/pyqtgraph/pyqtgraph` – Christian Nov 19 '18 at 12:45
  • If I use the development version of PyQtgraph and PySide2 5.6.0.1a my Graph is not working with the given code above. Th y axis is stuck somwhere between 1.0003 and the last digits are changing very fast. Any Ideas? – Sebus Jan 22 '19 at 09:30
  • @Sebus I recommend using the latest version of PySide2: 5.12, it's probably an old bug. – eyllanesc Jan 22 '19 at 17:33
  • @eyllanesc: Thank you! It works better, however I am then getting following Error message with the mousemove Event. Graph is working though: Traceback (most recent call last): File "C:\Python35\lib\site-packages\pyqtgraph\widgets\GraphicsView.py", line 365, in mouseMoveEvent delta = Point(ev.pos() - self.lastMousePos) TypeError: 'PySide2.QtCore.QPoint.__sub__' called with wrong argument types: PySide2.QtCore.QPoint.__sub__(Point) Supported signatures: PySide2.QtCore.QPoint.__sub__(PySide2.QtCore.QPoint) – Sebus Jan 23 '19 at 11:01
  • Is this still true in 2020? – Jim Feb 07 '20 at 20:39
  • @Jim Explain yourself better, I don't understand your question – eyllanesc Feb 07 '20 at 20:44
  • This question was asked in 2018, the accepted answer was how to work around a feature in progress. its now 2020 I expected the feature to be live by now but I was seeing the same issue. It seems the answer today, in 2020, is to use PySide2.QtChart instead of pyqtgraph directly – Jim Feb 07 '20 at 21:14
  • @Jim The new version of pyqtgraph is still being developed (it is in beta) so my answer is still valid. Using QtCharts is another option that has nothing to do with the OP's question. IMHO Qt Charts has not gained much affection from Qt (it has many limitations) also must include PySide2 bugs with that module so if they gave me my choice I would still use pyqtgraph (obviously the development branch + some patch necessary) – eyllanesc Feb 07 '20 at 21:20
0

For anyone else getting errors with Point - I manually imported from 'PySide2.QtCore import QPoint' into the files giving me an error and changed Point to QPoint. Not anything official but fixes it for now.

View fix here https://github.com/pyqtgraph/pyqtgraph/pull/818/files