4

So I am making a GUI using Pyqt6 and want to add graphs inside the Gui with other data, SO when I try adding the graph i get the error bellow:

call: addWidget(self, QWidget): argument 1 has unexpected type 'PlotWidget' addWidget(self, QWidget, int, int, alignment: Qt.AlignmentFlag = Qt.Alignment()): argument 1 has unexpected type 'PlotWidget' addWidget(self, QWidget, int, int, int, int, alignment: Qt.AlignmentFlag = Qt.Alignment()): argument 1 has unexpected type 'PlotWidget'

The code I have

    self.plt=pyqtgraph.PlotWidget()
    self.plt.plot([1,2,3,4,5],[1,2,3,4,5])
    grid.addWidget(self.plt, 6, 1, 3, 3)
    self.setLayout(grid)  #up I have grid=QGridLayout()
3
  • It would help too see minimal working example with imports as well. Also which version of pyqtgraph You are using. You can try to upgrade it to newest version with python3 -m pip install pyqtgraph --upgrade Commented Jan 28, 2022 at 11:44
  • @Domarm I upgraded but it doesn't show anything different, still getting the same error. Commented Jan 28, 2022 at 17:33
  • @Ahmed please add a valid minimal reproducible example including the imports. Commented Jan 28, 2022 at 17:45

1 Answer 1

1

I was trying to reproduce Your issue for a while.
I succeeded after I install PyQt5 and PyQt6 together in the same environment.

As @musicamante pointed out, it's important to first import PyQt6 and ONLY after that pyqtgraph. Otherwise QT_LIB is not set properly and only guesses PyQt version from already installed packages in the environment.

Sign up to request clarification or add additional context in comments.

6 Comments

This is probably due to the way pyqtgraph "guesses" the backend, which can be restricted by the proper import statements (which we asked to the OP, but were never provided). In which order did you import those libraries?
Yes, I believe so. Well, he didn't have to import PyQt5. It was enough to have it installed in the environment. So even valid minimal example would not help in this case.
Having both versions should never be an issue, and importing PyQt first should solve the problem as pyqtgraph is normally able to properly detect the already imported Qt binding on its own. Otherwise, it must be reported to the project as a possible bug.
You are absolutely right. I dig up a bit and found out QT_LIB constant, which detects PyQt version. For installation with both PyQt5 and 6, it yields PyQt5.
And importing PyQt6 before pyqtgraph solves the problem?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.