【问题标题】:PySide2.QtWidgets.QxxxxLayout.addWidget called with wrong argument typesPySide2.QtWidgets.QxxxxLayout.addWidget 用错误的参数类型调用
【发布时间】:2019-05-25 11:02:26
【问题描述】:

我正在尝试使用 addWidget 功能将 FigureCanvasQTAgg 参数作为小部件添加到某些布局中,但发生了 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)

【问题讨论】:

  • 这可能只是一种解决方法,但您是否尝试过从addWidget 的第一次重载中明确设置默认值?
  • 是的,我已经尝试过这种解决方法,但没有成功。

标签: python python-3.x pyinstaller pyside2


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我也有类似的问题。

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-15
      • 1970-01-01
      • 1970-01-01
      • 2019-12-23
      • 2012-10-19
      • 1970-01-01
      相关资源
      最近更新 更多