Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python I';我使用了一个与Qtable小部件相关的类,但它没有';不显示在qmain窗口中_Python_Pyqt_Pyqt5_Pyside_Pyside2 - Fatal编程技术网

Python I';我使用了一个与Qtable小部件相关的类,但它没有';不显示在qmain窗口中

Python I';我使用了一个与Qtable小部件相关的类,但它没有';不显示在qmain窗口中,python,pyqt,pyqt5,pyside,pyside2,Python,Pyqt,Pyqt5,Pyside,Pyside2,我无法在应用程序类中显示DataEntryForm类,即在QMainWindow中。非常感谢你 #QWidget,包含我想要显示的QTableWidget的widget class DataEntryForm(QWidget): def __int__(self): super().__init__() self.item = 0 self.data = {"Phone L": 50.5} # lef

我无法在应用程序类中显示DataEntryForm类,即在QMainWindow中。非常感谢你

#QWidget,包含我想要显示的QTableWidget的widget

class DataEntryForm(QWidget):
    def __int__(self):
        super().__init__()

        self.item = 0
        self.data = {"Phone L": 50.5}

        # leftside
        self.table = QTableWidget()
        self.table.setColumnCount(2)
        self.table.setHorizontalHeaderLabels('Descriptions', 'Price')
        self.table.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

        self.layout = QHBoxLayout()
        self.layout.addWidget(self.table, 50)
        self.setLayout(self.layout)
#QMainWindow,我想显示这个类中的数据输入表单类

class App(QMainWindow):
    def __init__(self, widget):
        super().__init__()
        self.title = 'Hello, world!'
        self.setWindowTitle(self.title)
        self.resize(1200, 600)
        self.menuBar = self.menuBar()
        self.fileMenu = self.menuBar.addMenu('File')

        # export to csv file action
        exportAction = QAction('Export to csv', self)
        exportAction.setShortcut('Ctrl+E')

        self.setWindowIcon(QIcon('data-analysis_icon-icons.com_52842.ico'))
        # exportAction.triggered.connect

        # exit Action
        exitAction = QAction('Exit', self)
        exitAction.setShortcut("Ctrl+Q")
        exitAction.triggered.connect(lambda: app.quit())

        self.fileMenu.addAction(exportAction)
        self.fileMenu.addAction(exitAction)





if __name__ == '__main__':
    app = QApplication(sys.argv)
    x = DataEntryForm()
    ex = App(x)
    ex.show()
    sys.exit(app.exec_())

QMainWindow是一种特殊类型的QWidget,它使用显示其主要内容的。虽然您正确地创建了
DataEntryForm
的实例,但您只是将其作为参数添加到主窗口构造函数中,而没有对其进行任何处理

要使用该小部件,请使用
setCentralWidget()

提示:避免不同类型的类和实例使用相似的名称
app
是QApplication的实例,
app
是QMainWindow类。对该类使用不同的和更相关的东西,比如“MainWindow”

class App(QMainWindow):
    def __init__(self, widget):
        super().__init__()
        self.setCentralWidget(widget)
        # ...