未绑定方法的第一个参数必须具有类型'QWidget'

时间:2019-06-08 17:23:47

标签: python pyqt pyqt5

我正在尝试使用PyQt5和Python 3.7构建GUI应用程序,并且我决定在不同模块中破坏代码。当我尝试导入创建自定义窗口小部件实例的函数时,出现与“ sis”相关的错误。我读到的是,“ sis”是封装C / C ++代码以在python中运行的一种方式。但是我该如何处理呢? 这是运行该应用程序的代码:

import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow

class MainWindow(QMainWindow):

    def __init__(self):
        super(MainWindow, self).__init__()
        self.setGeometry(10,35,1500,800)
        self.setWindowTitle("Cotizador TuCheff")
        #self.setWindowIcon(QtGui.QIcon(''))
        mainWindow(self)


    def mainWindow(self):
        from PyQt5 import QtCore, QtGui, QtWidgets
        from Pages.Quote import quote


        barMenu = QtWidgets.QTabWidget(self)

        tab1 = QtWidgets.QWidget()

        quoteLayout = QtWidgets.QVBoxLayout()
        quoteGenerator = quote.makeQuoteWindow()
        quoteLayout.addWidget(quoteGenerator)
        tab1.setLayout(quoteLayout)

        barMenu.addTab(tab1, "&Nueva Cotización")


        self.setCentralWidget(barMenu)


if __name__ == "__main__":
    app = QApplication([])
    window = MainWindow()
    window.show()
    app.exec_()

我尝试获取自定义小部件的文件是:

from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QApplication
import sys



def makeQuoteWindow():
    quoteWindow = QuoteWindow
    quoteWindow.create()
    #app = QApplication([])
    #window = quoteWindow()
    #window.show()
    #status = app.exec_()
    #sys.exit(status)


class QuoteWindow(QtWidgets.QWidget):

    def __init__(self):
        super(QuoteWindow, self).__init__()

        def create(self):

            mainWidget = QtWidgets.QWidget()
            vLayout1 = QtWidgets.QVBoxLayout()



            #=======------------------------ UPPER SIDE -------------------

            hLayout1 = QtWidgets.QHBoxLayout()


            ##A LOT OF WIDGETS AND LAYOUTS

            hLayout2 = QtWidgets.QHBoxLayout()


            #display content
            vLayout1.addLayout(hLayout1)
            vLayout1.addLayout(hLayout2)
            hLayout2.addItem(vSpacer1)
            mainWidget.setLayout(vLayout1)

            return mainWidget


if __name__ == "__main__":
    makeQuoteWindow()

错误是:

TypeError: create(self, window: sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True): first argument of unbound method must have type 'QWidget'

1 个答案:

答案 0 :(得分:0)

尝试一下:

main.py

import sys
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtWidgets import QApplication, QMainWindow

#        from Pages.Quote import quote
from Quote import QuoteWindow


class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.setGeometry(10,35,1500,800)
        self.setWindowTitle("Cotizador TuCheff")
        self.setWindowIcon(QtGui.QIcon('im.png'))

#        mainWindow(self)
        self.mainWindow()

    def mainWindow(self):
#        from Pages.Quote import quote
        self.quoteWindow = QuoteWindow()             # +++

        barMenu = QtWidgets.QTabWidget(self)

        tab1 = QtWidgets.QWidget()

        quoteLayout = QtWidgets.QVBoxLayout()

#        quoteGenerator = quote.makeQuoteWindow()
#        quoteLayout.addWidget(quoteGenerator)
        quoteLayout.addWidget(self.quoteWindow)       # +++

        tab1.setLayout(quoteLayout)
        barMenu.addTab(tab1, "&Nueva Cotización")
        self.setCentralWidget(barMenu)


if __name__ == "__main__":
    app = QApplication([])
    window = MainWindow()
    window.show()
    app.exec_()

Quote.py

from PyQt5 import QtCore, QtWidgets, QtGui

class QuoteWindow(QtWidgets.QWidget):
    def __init__(self):
        super(QuoteWindow, self).__init__()

    def create(self):
        mainWidget = QtWidgets.QWidget()
        vLayout1 = QtWidgets.QVBoxLayout()

        #=======------------------------ UPPER SIDE -------------------
        hLayout1 = QtWidgets.QHBoxLayout()

        ##A LOT OF WIDGETS AND LAYOUTS
        hLayout2 = QtWidgets.QHBoxLayout()

        #display content
        vLayout1.addLayout(hLayout1)
        vLayout1.addLayout(hLayout2)
        hLayout2.addItem(vSpacer1)
        mainWidget.setLayout(vLayout1)

        return mainWidget

enter image description here