PySide2.QtWidgets.QxxxxLayout.addWidget用错误的参数类型调用

时间:2019-05-25 11:02:26

标签: python python-3.x pyinstaller pyside2

我正在尝试使用addWidget函数将TypeCanvasQTAgg参数作为小部件添加到某些布局,并且发生TypeError。仅当尝试运行使用pyinstaller构建的独立应用程序时,此错误才适用。直接运行脚本时,一切正常。

我正在使用python=3.6PySide2=5.12.3pyInstaller=3.4

from PySide2.QtWidgets import QApplication, QMainWindow, QMessageBox, QLineEdit, QComboBox, QWidget
import matplotlib
matplotlib.use("Qt5Agg")
from PySide2.QtCore import Qt
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure

class TasksConfigCreatorAdapter(QMainWindow):
    def __init__(self):
        super(TasksConfigCreatorAdapter, self).__init__()
        self.dialog = Ui_TasksConfigCreatorDialog()
        self.dialog.setupUi(self)  
        self.figure = None
        self.setupCanvasLayout()

    def setupCanvasLayout(self):
        if self.figure is None:
            self.figure = plt.figure()
            self.canvas = FigureCanvas(self.figure)
            self.figure.set_facecolor("white")
            self.toolbar = NavigationToolbar(self.canvas, None)
            self.dialog.canvasLayout.addWidget(self.canvas, *(0, 0))
            self.dialog.canvasLayout.addWidget(self.toolbar, *(1, 0))
TypeError: 'PySide2.QtWidgets.QGridLayout.addWidget' called with wrong argument types:
  PySide2.QtWidgets.QGridLayout.addWidget(FigureCanvasQTAgg, int, int)
Supported signatures:
  PySide2.QtWidgets.QGridLayout.addWidget(PySide2.QtWidgets.QWidget, int, int, PySide2.QtCore.Qt.Alignment=Default(Qt.Alignment))
  PySide2.QtWidgets.QGridLayout.addWidget(PySide2.QtWidgets.QWidget, int, int, int, int, PySide2.QtCore.Qt.Alignment=Default(Qt.Alignment))
  PySide2.QtWidgets.QGridLayout.addWidget(PySide2.QtWidgets.QWidget)

2 个答案:

答案 0 :(得分:0)

通过向规范文件中的排除列表添加PyQt5模块来解决此问题。 尝试在一个文件夹模式下创建独立文件时,我发现添加了PyQt5个文件以及PySide2个文件,这些文件会中断并导致发生此问题。

答案 1 :(得分:0)

我有一个类似的问题。

TypeError: 'qRegisterResourceData' called with wrong argument types:
  qRegisterResourceData(int, str, str, str)
Supported signatures:
  qRegisterResourceData(int, unicode, unicode, unicode)

我的错误是我使用的是Python3,没有使用-py3标志来编译qrc文件,其中默认值为Python2。

Usage: C:\Python36\Lib\site-packages\PySide\pyside-rcc.exe  [options] <inputs>

Options:
    -o file           Write output to file rather than stdout
    -py2              Generate code for any Python v2.x version (default)
    -py3              Generate code for any Python v3.x version
    -name name        Create an external initialization function with name
    -threshold level  Threshold to consider compressing files
    -compress level   Compress input files by level
    -root path        Prefix resource access path with root path
    -no-compress      Disable all compression
    -version          Display version
    -help             Display this information