I have been looking for a working example how to embed a matplotlib plot in pyside that is created with the QT designer while keeping the logic in a separate file. I know that there are numerous examples on the web but none of them actually uses the QT designer and then creates a separate file to add the logic where the matplitlib plot is added to a widget. I found an example that 'almost' works http://blog.rcnelson.com/building-a-matplotlib-gui-with-qt-designer-part-1/ but but in my version it's not possible to "Change the layoutName property from “verticalLayout” to “mplvl”".
So I have the following specific questions: I'm not clear into what item that plot can be embedded to in Pyside Qt designer. Is it a simple "widget" (as there is no matplotlib widget available in pyside). If so, how can I then add the plot to that widget? Or do I have to create a 'FigureCanvas' with Qt Designer? Is this possible at all? If so, how?
Here is the simplest possible design I can make with the Pyside Qt designer in embedding a widget (is this correct?). How can I now add a matplotlib plot on top of it?
As suggested in one of the answers I have now promoted the Qwidget to MyStaticMplCanvas and edited the name of Qwidget to mplvl.
Automatically generated file with Pyside Qt designer and compiled with pyside-uic ui.ui -o ui.py -x
ui.py looks like this:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'gui.ui'
#
# Created: Wed Apr 20 14:00:02 2016
# by: pyside-uic 0.2.15 running on PySide 1.2.2
#
# WARNING! All changes made in this file will be lost!
from PySide import QtCore, QtGui
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(444, 530)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.mplvl = MyStaticMplCanvas(self.centralwidget)
self.mplvl.setGeometry(QtCore.QRect(120, 190, 221, 161))
self.mplvl.setObjectName("mplvl")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtGui.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 444, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtGui.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
from mystaticmplcanvas import MyStaticMplCanvas
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
how can I now add a plot into the mplvl object from a separate .py file?