我試圖使用自定義窗口小部件添加到qtdesginer下面的代碼錯誤添加matplotlib工具到PyQt4的
from PyQt4 import QtGui
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
import PySide
from matplotlib.figure import Figure
class MplCanvas(FigureCanvas):
def __init__(self):
self.fig = Figure()
self.ax = self.fig.add_subplot(111)
FigureCanvas.__init__(self, self.fig)
FigureCanvas.setSizePolicy(self, QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
class MplWidget(QtGui.QWidget):
def __init__(self, parent = None):
QtGui.QWidget.__init__(self, parent)
self.canvas = MplCanvas()
self.vbl = QtGui.QVBoxLayout()
self.vbl.addWidget(self.canvas)
self.setLayout(self.vbl)
但我只給我
類型錯誤的錯誤:「PySide.QtGui.QWidget .setSizePolicy」調用錯誤的參數類型: PySide.QtGui.QWidget.setSizePolicy(方針,政策) 支持的簽名: PySide.QtGui.QWidget.setSizePolicy(PySide.QtGui.QSizePolicy) PySide.QtGui.QWidget.setSizePolicy( PySide.QtGui.QSizePolicy.Policy,PySide.QtGui。 QSizePolicy.Policy)
我並不確切知道是什麼原因造成的錯誤,因爲我bascially遵循了這一部分http://packtlib.packtpub.com/library/9781847197900/ch06lvl1sec04
任何建議將是很好的,因爲我是新來這個Qt設計。
您不能混用' PyQt4'和'PySides' – tacaswell