【发布时间】:2021-02-09 20:53:42
【问题描述】:
我无法在 App 类中显示 DataEntryForm 类,即在 QMainWindow 中。非常感谢。
#QWidget,包含我要显示的 QTableWidget 的小部件
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,我想在这个类中显示Data Entry Form类。
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_())
【问题讨论】:
标签: python pyqt pyqt5 pyside pyside2