好友
阅读权限10
听众
最后登录1970-1-1
|
想用Qtdesigner做一个类似Excel的表格,设计完了之后预览一切正常。但是转换成py文件再运行,就出BUG了。求大神解惑~~
以下是UI文件转换成的py文件代码:
[Python] 纯文本查看 复制代码 # -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'test_UI.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(1830, 1259)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("../Icon/cog_icon_x_128px_1077765_easyicon.net.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
Form.setWindowIcon(icon)
self.verticalLayout_4 = QtWidgets.QVBoxLayout(Form)
self.verticalLayout_4.setContentsMargins(40, 20, 40, 40)
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.verticalLayout_3 = QtWidgets.QVBoxLayout()
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.frame = QtWidgets.QFrame(Form)
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.frame)
self.horizontalLayout.setObjectName("horizontalLayout")
self.pushButton = QtWidgets.QPushButton(self.frame)
self.pushButton.setObjectName("pushButton")
self.horizontalLayout.addWidget(self.pushButton)
self.pushButton_2 = QtWidgets.QPushButton(self.frame)
self.pushButton_2.setObjectName("pushButton_2")
self.horizontalLayout.addWidget(self.pushButton_2)
spacerItem = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
self.horizontalLayout.addItem(spacerItem)
self.verticalLayout_3.addWidget(self.frame)
self.tabWidget = QtWidgets.QTabWidget(Form)
self.tabWidget.setLayoutDirection(QtCore.Qt.LeftToRight)
self.tabWidget.setTabPosition(QtWidgets.QTabWidget.West)
self.tabWidget.setObjectName("tabWidget")
self.tab = QtWidgets.QWidget()
self.tab.setObjectName("tab")
self.verticalLayout = QtWidgets.QVBoxLayout(self.tab)
self.verticalLayout.setObjectName("verticalLayout")
self.label = QtWidgets.QLabel(self.tab)
self.label.setObjectName("label")
self.verticalLayout.addWidget(self.label, 0, QtCore.Qt.AlignHCenter)
self.tableWidget = QtWidgets.QTableWidget(self.tab)
self.tableWidget.setTabletTracking(False)
self.tableWidget.setAutoFillBackground(True)
self.tableWidget.setRowCount(50)
self.tableWidget.setColumnCount(26)
self.tableWidget.setObjectName("tableWidget")
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(2, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(3, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(4, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(5, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(6, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(7, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(8, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(9, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(10, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(11, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(12, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(13, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(14, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(15, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(16, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(17, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(18, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(19, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(20, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(21, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(22, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(23, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(24, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(25, item)
self.tableWidget.horizontalHeader().setDefaultSectionSize(90)
self.tableWidget.horizontalHeader().setMinimumSectionSize(30)
self.tableWidget.verticalHeader().setDefaultSectionSize(28)
self.tableWidget.verticalHeader().setMinimumSectionSize(20)
self.verticalLayout.addWidget(self.tableWidget)
self.tabWidget.addTab(self.tab, "")
self.tab_2 = QtWidgets.QWidget()
self.tab_2.setObjectName("tab_2")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.tab_2)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.label_2 = QtWidgets.QLabel(self.tab_2)
self.label_2.setObjectName("label_2")
self.verticalLayout_2.addWidget(self.label_2, 0, QtCore.Qt.AlignHCenter)
self.tableWidget_2 = QtWidgets.QTableWidget(self.tab_2)
self.tableWidget_2.setTabletTracking(False)
self.tableWidget_2.setAutoFillBackground(True)
self.tableWidget_2.setRowCount(50)
self.tableWidget_2.setColumnCount(26)
self.tableWidget_2.setObjectName("tableWidget_2")
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(2, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(3, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(4, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(5, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(6, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(7, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(8, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(9, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(10, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(11, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(12, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(13, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(14, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(15, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(16, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(17, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(18, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(19, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(20, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(21, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(22, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(23, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(24, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget_2.setHorizontalHeaderItem(25, item)
self.tableWidget_2.horizontalHeader().setDefaultSectionSize(90)
self.tableWidget_2.horizontalHeader().setMinimumSectionSize(30)
self.tableWidget_2.verticalHeader().setDefaultSectionSize(28)
self.tableWidget_2.verticalHeader().setMinimumSectionSize(20)
self.verticalLayout_2.addWidget(self.tableWidget_2)
self.tabWidget.addTab(self.tab_2, "")
self.verticalLayout_3.addWidget(self.tabWidget)
self.verticalLayout_4.addLayout(self.verticalLayout_3)
self.retranslateUi(Form)
self.tabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "test_Ui"))
self.pushButton.setText(_translate("Form", "Save"))
self.pushButton_2.setText(_translate("Form", "Cancel"))
self.label.setText(_translate("Form", "<html><head/><body><p><span style=\" font-size:16pt; font-weight:600;\">Table</span></p></body></html>"))
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(_translate("Form", "A"))
item = self.tableWidget.horizontalHeaderItem(1)
item.setText(_translate("Form", "B"))
item = self.tableWidget.horizontalHeaderItem(2)
item.setText(_translate("Form", "C"))
item = self.tableWidget.horizontalHeaderItem(3)
item.setText(_translate("Form", "D"))
item = self.tableWidget.horizontalHeaderItem(4)
item.setText(_translate("Form", "E"))
item = self.tableWidget.horizontalHeaderItem(5)
item.setText(_translate("Form", "F"))
item = self.tableWidget.horizontalHeaderItem(6)
item.setText(_translate("Form", "G"))
item = self.tableWidget.horizontalHeaderItem(7)
item.setText(_translate("Form", "H"))
item = self.tableWidget.horizontalHeaderItem(8)
item.setText(_translate("Form", "I"))
item = self.tableWidget.horizontalHeaderItem(9)
item.setText(_translate("Form", "J"))
item = self.tableWidget.horizontalHeaderItem(10)
item.setText(_translate("Form", "K"))
item = self.tableWidget.horizontalHeaderItem(11)
item.setText(_translate("Form", "L"))
item = self.tableWidget.horizontalHeaderItem(12)
item.setText(_translate("Form", "M"))
item = self.tableWidget.horizontalHeaderItem(13)
item.setText(_translate("Form", "N"))
item = self.tableWidget.horizontalHeaderItem(14)
item.setText(_translate("Form", "O"))
item = self.tableWidget.horizontalHeaderItem(15)
item.setText(_translate("Form", "P"))
item = self.tableWidget.horizontalHeaderItem(16)
item.setText(_translate("Form", "Q"))
item = self.tableWidget.horizontalHeaderItem(17)
item.setText(_translate("Form", "R"))
item = self.tableWidget.horizontalHeaderItem(18)
item.setText(_translate("Form", "S"))
item = self.tableWidget.horizontalHeaderItem(19)
item.setText(_translate("Form", "T"))
item = self.tableWidget.horizontalHeaderItem(20)
item.setText(_translate("Form", "U"))
item = self.tableWidget.horizontalHeaderItem(21)
item.setText(_translate("Form", "V"))
item = self.tableWidget.horizontalHeaderItem(22)
item.setText(_translate("Form", "W"))
item = self.tableWidget.horizontalHeaderItem(23)
item.setText(_translate("Form", "X"))
item = self.tableWidget.horizontalHeaderItem(24)
item.setText(_translate("Form", "Y"))
item = self.tableWidget.horizontalHeaderItem(25)
item.setText(_translate("Form", "Z"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), _translate("Form", "Tab 1"))
self.label_2.setText(_translate("Form", "<html><head/><body><p><span style=\" font-size:16pt; font-weight:600;\">附表1</span></p></body></html>"))
item = self.tableWidget_2.horizontalHeaderItem(0)
item.setText(_translate("Form", "A"))
item = self.tableWidget_2.horizontalHeaderItem(1)
item.setText(_translate("Form", "B"))
item = self.tableWidget_2.horizontalHeaderItem(2)
item.setText(_translate("Form", "C"))
item = self.tableWidget_2.horizontalHeaderItem(3)
item.setText(_translate("Form", "D"))
item = self.tableWidget_2.horizontalHeaderItem(4)
item.setText(_translate("Form", "E"))
item = self.tableWidget_2.horizontalHeaderItem(5)
item.setText(_translate("Form", "F"))
item = self.tableWidget_2.horizontalHeaderItem(6)
item.setText(_translate("Form", "G"))
item = self.tableWidget_2.horizontalHeaderItem(7)
item.setText(_translate("Form", "H"))
item = self.tableWidget_2.horizontalHeaderItem(8)
item.setText(_translate("Form", "I"))
item = self.tableWidget_2.horizontalHeaderItem(9)
item.setText(_translate("Form", "J"))
item = self.tableWidget_2.horizontalHeaderItem(10)
item.setText(_translate("Form", "K"))
item = self.tableWidget_2.horizontalHeaderItem(11)
item.setText(_translate("Form", "L"))
item = self.tableWidget_2.horizontalHeaderItem(12)
item.setText(_translate("Form", "M"))
item = self.tableWidget_2.horizontalHeaderItem(13)
item.setText(_translate("Form", "N"))
item = self.tableWidget_2.horizontalHeaderItem(14)
item.setText(_translate("Form", "O"))
item = self.tableWidget_2.horizontalHeaderItem(15)
item.setText(_translate("Form", "P"))
item = self.tableWidget_2.horizontalHeaderItem(16)
item.setText(_translate("Form", "Q"))
item = self.tableWidget_2.horizontalHeaderItem(17)
item.setText(_translate("Form", "R"))
item = self.tableWidget_2.horizontalHeaderItem(18)
item.setText(_translate("Form", "S"))
item = self.tableWidget_2.horizontalHeaderItem(19)
item.setText(_translate("Form", "T"))
item = self.tableWidget_2.horizontalHeaderItem(20)
item.setText(_translate("Form", "U"))
item = self.tableWidget_2.horizontalHeaderItem(21)
item.setText(_translate("Form", "V"))
item = self.tableWidget_2.horizontalHeaderItem(22)
item.setText(_translate("Form", "W"))
item = self.tableWidget_2.horizontalHeaderItem(23)
item.setText(_translate("Form", "X"))
item = self.tableWidget_2.horizontalHeaderItem(24)
item.setText(_translate("Form", "Y"))
item = self.tableWidget_2.horizontalHeaderItem(25)
item.setText(_translate("Form", "Z"))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), _translate("Form", "Tab 2"))
以下是用来运行的代码:
[Python] 纯文本查看 复制代码 import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QApplication, QMenu, QTableWidgetItem
from PyQt5.QtCore import QObject, Qt
from test_UI import *
class MyMainWindow(QMainWindow, Ui_Form):
def __init__(self):
super(MyMainWindow, self).__init__()
self.setupUi(self)
if __name__ == "__main__":
app = QApplication(sys.argv)
win = MyMainWindow()
win.show()
sys.exit(app.exec_())
再贴一下两张截图:
|
-
代码运行图
-
Qtdesigner里的预览图
|