Выдаёт такую ошибку:
Traceback (most recent call last):
File "C:\Python34\ORGHaniser.py", line 29, in
widget = ORGH_widget()
File "C:\Python34\ORGHaniser.py", line 7, in __init__
self.maindialog = ORGH_app(None)
File "C:\Python34\ORGHaniser.py", line 17, in __init__
Ui_Form.setupUi(self, ORGH_app)
File "C:\Python34\ORGHaniser_ui.py", line 5, in setupUi
Form.setObjectName("Form")
TypeError: QObject.setObjectName(str): first argument of unbound method must have type 'QObject'
Код:
from PyQt5 import QtCore, QtGui, QtWidgets
from ORGHaniser_ui import Ui_Form
import sys
class ORGH_widget(QtWidgets.QWidget):
def __init__(self, parent=None):
super(ORGH_widget, self).__init__(parent)
self.maindialog = ORGH_app(None)
self.setMainWidget(self.maindialog)
self.maindialog.show()
self.exec_loop()
def keyPressEvent(self, e):
if e.key() == Qt.Key_Escape:
self.close()
class ORGH_app(Ui_Form, QtWidgets.QMainWindow):
def __init__(self,parent):
Ui_Form.setupUi(self, ORGH_app)
self._connectSlots()
def _connectSlots(self):
Ui_Form.pushButton.clicked.connect(self.lineedit,self._slotAddClicked)
def _slotAddClicked(self):
text = self.lineedit.text()
if len(text):
tvi = QTableViewItem(self.tableview)
tvi.setText(0,text)
self.lineedit.clear()
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
widget = ORGH_widget()
sys.exit(app.exec())
Код UI:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(400, 300)
self.tableView = QtWidgets.QTableView(Form)
self.tableView.setGeometry(QtCore.QRect(10, 10, 381, 251))
self.tableView.setObjectName("tableView")
self.lineEdit = QtWidgets.QLineEdit(Form)
self.lineEdit.setGeometry(QtCore.QRect(10, 270, 301, 20))
self.lineEdit.setObjectName("lineEdit")
self.pushButton = QtWidgets.QPushButton(Form)
self.pushButton.setGeometry(QtCore.QRect(320, 270, 75, 23))
self.pushButton.setObjectName("pushButton")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.lineEdit.setText(_translate("Form", "USER */%/# +n/-n"))
self.pushButton.setText(_translate("Form", "OK"))