PySide2.QtWidgets.QxxxxLayout.addWidget 使用错误的参数类型调用
PySide2.QtWidgets.QxxxxLayout.addWidget called with wrong argument types
我正在尝试使用 addWidget 函数将 FigureCanvasQTAgg 参数作为小部件添加到某些布局,但出现了 TypeError。只有在尝试 运行 我使用 pyinstaller 构建的独立应用程序时才会出现此错误。当 运行 直接使用脚本时一切正常。
我正在使用 python=3.6
、PySide2=5.12.3
、pyInstaller=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)
通过将 PyQt5
模块添加到规范文件中的排除列表来解决此问题。
当尝试在一个文件夹模式下创建独立文件时,我发现添加了 PyQt5
个文件以及 PySide2
个文件,这些文件会中断并导致此问题发生。
我遇到了类似的问题。
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
我正在尝试使用 addWidget 函数将 FigureCanvasQTAgg 参数作为小部件添加到某些布局,但出现了 TypeError。只有在尝试 运行 我使用 pyinstaller 构建的独立应用程序时才会出现此错误。当 运行 直接使用脚本时一切正常。
我正在使用 python=3.6
、PySide2=5.12.3
、pyInstaller=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)
通过将 PyQt5
模块添加到规范文件中的排除列表来解决此问题。
当尝试在一个文件夹模式下创建独立文件时,我发现添加了 PyQt5
个文件以及 PySide2
个文件,这些文件会中断并导致此问题发生。
我遇到了类似的问题。
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