0

Since QT5 is out since 5 years, I wonder that this simple question still has no answer I could find.

I am using python(2.7.13) with anaconda packages:

qt    5.6.2
qtpy  1.3.1

I want to be able to use QT designer to graphically design a UI, which uses an interactive matplotlib window/plot. I found examples, using QT4, but cannot figure out how to do this in QT5. Is there something like the matplotlibwidget for QT5?

Edit: I want to use QT designer to have my interface and my logic separated from each other. I usually use pyuic to turn my *.ui files into *.py files. I am looking for a compatible (or better) workflow, so that I can keep using a graphical editor (like QT designer) and have my logic and ui separated and be able to use matplotlib figures inside my ui.

Dschoni
  • 3,714
  • 6
  • 45
  • 80
  • 1
    I don't quite understand the problem. There is a [PyQt5 example](https://matplotlib.org/examples/user_interfaces/embedding_in_qt5.html) on the matplotlib page. Appart, you can use almost any pyqt4 example you find and change the imports, such that it works with pyqt5. – ImportanceOfBeingErnest Sep 29 '17 at 08:13
  • In [this answer](https://stackoverflow.com/a/42624276/4124317) versions for pyqt4 and 5 are given next to each other. In [this answer](https://stackoverflow.com/questions/44472494/matplotlib-figure-plot-canvas-layout-hides-buttons) you see another case where changing between 4 and 5 is just replacing two lines of code. [This thread](https://stackoverflow.com/a/42774310/4124317) might be of interest as well, because an initial pyqt4 answer is changed to pyqt5 in another answer to the question, allowing to see the differences. – ImportanceOfBeingErnest Sep 29 '17 at 08:23
  • I'm looking for a way to design that UI graphically i.e. using QT designer. How does any of this answers solve that problem? – Dschoni Oct 04 '17 at 09:17
  • 1
    You would design your UI with Qt designer and then add the FigureCanvas widget to the layout. There isn't really any difference except that the code generated by Qtdesigner usually adds a lot of unnecessary stuff, which is why its not well suited for code examples on SO. – ImportanceOfBeingErnest Oct 04 '17 at 09:25
  • Thanks, this pushes me in the right direction. So, I create a *.ui file with QT designer, compile it to python (via pyuic). I import that file into my real programm, that handles all the logic. So, is there any placeholder in QT designer (or widget), that I can use to load the FigureCanvas in? Or is my workflow just wrong? – Dschoni Oct 04 '17 at 09:42
  • 2
    No the logic is correct. In Qt designer you can just leave some space in a layout and in the "real program" you add the figure canvas to that layout. So if you have something like `self.canvas = FigureCanvas(figure)` you can add it to the layout with `.somewidget.layout().addWidget(self.canvas)`. You may use something like `self.canvas.setSizePolicy(self, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)` to make the FigureCanvas expand inside the layout. – ImportanceOfBeingErnest Oct 04 '17 at 11:45
  • Thanks. That worked. I use a layout itself as a spaceholder. – Dschoni Oct 04 '17 at 13:09

0 Answers0