Ошибка запуска окна скомпилированного в Qt Designer
Создал макет приложения в Qt Designer
, настроил все параметры и конвертировал командой в Python
код:
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QFrame, QGridLayout, QLabel,
QLineEdit, QMainWindow, QMenuBar, QPushButton,
QSizePolicy, QStatusBar, QWidget)
class Ui_OST_authorization(object):
def setupUi(self, OST_authorization):
if not OST_authorization.objectName():
OST_authorization.setObjectName(u"OST_authorization")
OST_authorization.resize(330, 381)
OST_authorization.setMinimumSize(QSize(330, 381))
OST_authorization.setMaximumSize(QSize(330, 395))
OST_authorization.setStyleSheet(u"QLineEdit#Name{\n"
" min-width: 310px;\n"
" min-height: 33px;\n"
" max-width: 310px;\n"
" max-height: 33px;\n"
"}\n"
"QLineEdit#Surname{\n"
" min-width: 310px;\n"
" min-height: 33px;\n"
" max-width: 310px;\n"
" max-height: 33px;\n"
"}\n"
"QLineEdit#Patronymic{\n"
" min-width: 310px;\n"
" min-height: 33px;\n"
" max-width: 310px;\n"
" max-height: 33px;\n"
"}\n"
"QLineEdit#Class{\n"
" min-width: 310px;\n"
" min-height: 33px;\n"
" max-width: 310px;\n"
" max-height: 33px;\n"
"}\n"
"QLineEdit#Series{\n"
" min-width: 310px;\n"
" min-height: 33px;\n"
" max-width: 310px;\n"
" max-height: 33px;\n"
"}\n"
"QLineEdit#Number{\n"
" min-width: 310px;\n"
" min-height: 33px;\n"
" max-width: 310px;\n"
" max-height: 33px;\n"
"}\n"
"QPushButton#Continue{\n"
" min-width: 310px;\n"
" min-height: 33px;\n"
" max-width: 310px;\n"
" max-height: 33px;\n"
"}\n"
"")
OST_authorization.setDocumentMode(True)
self.centralwidget = QWidget(OST_authorization)
self.centralwidget.setObjectName(u"centralwidget")
self.gridLayout = QGridLayout(self.centralwidget)
self.gridLayout.setObjectName(u"gridLayout")
self.Name = QLineEdit(self.centralwidget)
self.Name.setObjectName(u"Name")
self.Name.setEnabled(True)
self.Name.setMinimumSize(QSize(312, 35))
self.Name.setMaximumSize(QSize(312, 35))
self.Name.setStyleSheet(u"")
self.gridLayout.addWidget(self.Name, 5, 0, 1, 2)
self.AuthorizationLable = QLabel(self.centralwidget)
self.AuthorizationLable.setObjectName(u"AuthorizationLable")
self.gridLayout.addWidget(self.AuthorizationLable, 4, 0, 1, 2)
self.line = QFrame(self.centralwidget)
self.line.setObjectName(u"line")
self.line.setFrameShape(QFrame.Shape.HLine)
self.line.setFrameShadow(QFrame.Shadow.Sunken)
self.gridLayout.addWidget(self.line, 8, 0, 1, 2)
self.Class = QLineEdit(self.centralwidget)
self.Class.setObjectName(u"Class")
self.Class.setMinimumSize(QSize(312, 35))
self.Class.setMaximumSize(QSize(312, 35))
self.gridLayout.addWidget(self.Class, 9, 0, 1, 2)
self.line_2 = QFrame(self.centralwidget)
self.line_2.setObjectName(u"line_2")
self.line_2.setFrameShape(QFrame.Shape.HLine)
self.line_2.setFrameShadow(QFrame.Shadow.Sunken)
self.gridLayout.addWidget(self.line_2, 10, 0, 1, 2)
self.Series = QLineEdit(self.centralwidget)
self.Series.setObjectName(u"Series")
self.Series.setMinimumSize(QSize(312, 35))
self.Series.setMaximumSize(QSize(312, 35))
self.gridLayout.addWidget(self.Series, 11, 0, 1, 2)
self.Continue = QPushButton(self.centralwidget)
self.Continue.setObjectName(u"Continue")
self.Continue.setMinimumSize(QSize(312, 35))
self.Continue.setMaximumSize(QSize(312, 35))
self.gridLayout.addWidget(self.Continue, 14, 0, 1, 2)
self.line_3 = QFrame(self.centralwidget)
self.line_3.setObjectName(u"line_3")
self.line_3.setFrameShape(QFrame.Shape.HLine)
self.line_3.setFrameShadow(QFrame.Shadow.Sunken)
self.gridLayout.addWidget(self.line_3, 13, 0, 1, 2)
self.Patronymic = QLineEdit(self.centralwidget)
self.Patronymic.setObjectName(u"Patronymic")
self.Patronymic.setMinimumSize(QSize(312, 35))
self.Patronymic.setMaximumSize(QSize(312, 35))
self.gridLayout.addWidget(self.Patronymic, 7, 0, 1, 2)
self.Surname = QLineEdit(self.centralwidget)
self.Surname.setObjectName(u"Surname")
self.Surname.setMinimumSize(QSize(312, 35))
self.Surname.setMaximumSize(QSize(312, 35))
self.gridLayout.addWidget(self.Surname, 6, 0, 1, 2)
self.Number = QLineEdit(self.centralwidget)
self.Number.setObjectName(u"Number")
self.Number.setMinimumSize(QSize(312, 35))
self.Number.setMaximumSize(QSize(312, 35))
self.gridLayout.addWidget(self.Number, 12, 0, 1, 2)
OST_authorization.setCentralWidget(self.centralwidget)
self.menubar = QMenuBar(OST_authorization)
self.menubar.setObjectName(u"menubar")
self.menubar.setGeometry(QRect(0, 0, 330, 22))
OST_authorization.setMenuBar(self.menubar)
self.statusbar = QStatusBar(OST_authorization)
self.statusbar.setObjectName(u"statusbar")
OST_authorization.setStatusBar(self.statusbar)
self.retranslateUi(OST_authorization)
QMetaObject.connectSlotsByName(OST_authorization)
# setupUi
def retranslateUi(self, OST_authorization):
OST_authorization.setWindowTitle(QCoreApplication.translate("OST_authorization", u"OST - (\u0434\u0435\u043c\u043e \u0432\u0435\u0440\u0441\u0438\u044f)", None))
self.Name.setPlaceholderText(QCoreApplication.translate("OST_authorization", u"\u0418\u043c\u044f", None))
self.AuthorizationLable.setText(QCoreApplication.translate("OST_authorization", u"<html><head/><body><p><span style=\" font-size:12pt;\">\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f</span></p></body></html>", None))
self.Class.setPlaceholderText(QCoreApplication.translate("OST_authorization", u"\u041d\u043e\u043c\u0435\u0440 \u0438 \u0431\u0443\u043a\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430", None))
self.Series.setPlaceholderText(QCoreApplication.translate("OST_authorization", u"\u0421\u0435\u0440\u0438\u044f", None))
self.Continue.setText(QCoreApplication.translate("OST_authorization", u"\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c", None))
self.Patronymic.setPlaceholderText(QCoreApplication.translate("OST_authorization", u"\u041e\u0442\u0447\u0435\u0441\u0442\u0432\u043e (\u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438)", None))
self.Surname.setPlaceholderText(QCoreApplication.translate("OST_authorization", u"\u0424\u0430\u043c\u0438\u043b\u0438\u044f", None))
self.Number.setPlaceholderText(QCoreApplication.translate("OST_authorization", u"\u041d\u043e\u043c\u0435\u0440", None))
# retranslateUi
Создал файл для запуска программы, но столкнулся с ошибкой:
Traceback (most recent call last):
File "D:\Projects\ProjectsProgramming\PyCharmCommunity\OST\src\quiz\authorization.py", line 20, in <module>
authorization_window = Authorization()
^^^^^^^^^^^^^^^
File "D:\Projects\ProjectsProgramming\PyCharmCommunity\OST\src\quiz\authorization.py", line 13, in __init__
self.ui.setupUi(self)
File "D:\Projects\ProjectsProgramming\PyCharmCommunity\OST\src\ui\py\OST_authorization.py", line 27, in setupUi
OST_authorization.setMinimumSize(QSize(330, 381))
TypeError: arguments did not match any overloaded call:
setMinimumSize(self, minw: int, minh: int): argument 1 has unexpected type 'PySide6.QtCore.QSize'
setMinimumSize(self, s: QSize): argument 1 has unexpected type 'PySide6.QtCore.QSize'
Process finished with exit code 1
Код файла для запуска:
import sys
from PyQt6.QtWidgets import QApplication, QWidget
from src.ui.py.OST_authorization import Ui_OST_authorization
class Authorization(QWidget):
def __init__(self):
super().__init__()
self.ui = Ui_OST_authorization()
self.ui.setupUi(self)
self.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
authorization_window = Authorization()
sys.exit(app.exec())
Предполагаю, что требуется добавить какие либо модули, но какие и как исправить код?
Ответы (1 шт):
Автор решения: S. Nick
→ Ссылка
Во-первых, работайте с чем-то одним, или PySide6 или PyQt6.
Во-вторых, если вы в Qt Designer наследовались от QMainWindow
, то и файле для запуска надо наследоваться от класса QMainWindow()
.
import sys
'''
from PyQt6.QtWidgets import QApplication, QWidget
'''
from PyQt5.QtWidgets import QApplication, QWidget
from PyQt5.Qt import *
#from src.ui.py.OST_authorization import Ui_OST_authorization
'''
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QFrame, QGridLayout, QLabel,
QLineEdit, QMainWindow, QMenuBar, QPushButton,
QSizePolicy, QStatusBar, QWidget)
'''
class Ui_OST_authorization(object):
def setupUi(self, OST_authorization):
if not OST_authorization.objectName():
OST_authorization.setObjectName(u"OST_authorization")
OST_authorization.resize(330, 381)
OST_authorization.setMinimumSize(QSize(330, 381))
OST_authorization.setMaximumSize(QSize(330, 395))
OST_authorization.setStyleSheet(u"QLineEdit#Name{\n"
" min-width: 310px;\n"
" min-height: 33px;\n"
" max-width: 310px;\n"
" max-height: 33px;\n"
"}\n"
"QLineEdit#Surname{\n"
" min-width: 310px;\n"
" min-height: 33px;\n"
" max-width: 310px;\n"
" max-height: 33px;\n"
"}\n"
"QLineEdit#Patronymic{\n"
" min-width: 310px;\n"
" min-height: 33px;\n"
" max-width: 310px;\n"
" max-height: 33px;\n"
"}\n"
"QLineEdit#Class{\n"
" min-width: 310px;\n"
" min-height: 33px;\n"
" max-width: 310px;\n"
" max-height: 33px;\n"
"}\n"
"QLineEdit#Series{\n"
" min-width: 310px;\n"
" min-height: 33px;\n"
" max-width: 310px;\n"
" max-height: 33px;\n"
"}\n"
"QLineEdit#Number{\n"
" min-width: 310px;\n"
" min-height: 33px;\n"
" max-width: 310px;\n"
" max-height: 33px;\n"
"}\n"
"QPushButton#Continue{\n"
" min-width: 310px;\n"
" min-height: 33px;\n"
" max-width: 310px;\n"
" max-height: 33px;\n"
"}\n"
"")
OST_authorization.setDocumentMode(True)
self.centralwidget = QWidget(OST_authorization)
self.centralwidget.setObjectName(u"centralwidget")
self.gridLayout = QGridLayout(self.centralwidget)
self.gridLayout.setObjectName(u"gridLayout")
self.Name = QLineEdit(self.centralwidget)
self.Name.setObjectName(u"Name")
self.Name.setEnabled(True)
self.Name.setMinimumSize(QSize(312, 35))
self.Name.setMaximumSize(QSize(312, 35))
self.Name.setStyleSheet(u"")
self.gridLayout.addWidget(self.Name, 5, 0, 1, 2)
self.AuthorizationLable = QLabel(self.centralwidget)
self.AuthorizationLable.setObjectName(u"AuthorizationLable")
self.gridLayout.addWidget(self.AuthorizationLable, 4, 0, 1, 2)
self.line = QFrame(self.centralwidget)
self.line.setObjectName(u"line")
self.line.setFrameShape(QFrame.Shape.HLine)
self.line.setFrameShadow(QFrame.Shadow.Sunken)
self.gridLayout.addWidget(self.line, 8, 0, 1, 2)
self.Class = QLineEdit(self.centralwidget)
self.Class.setObjectName(u"Class")
self.Class.setMinimumSize(QSize(312, 35))
self.Class.setMaximumSize(QSize(312, 35))
self.gridLayout.addWidget(self.Class, 9, 0, 1, 2)
self.line_2 = QFrame(self.centralwidget)
self.line_2.setObjectName(u"line_2")
self.line_2.setFrameShape(QFrame.Shape.HLine)
self.line_2.setFrameShadow(QFrame.Shadow.Sunken)
self.gridLayout.addWidget(self.line_2, 10, 0, 1, 2)
self.Series = QLineEdit(self.centralwidget)
self.Series.setObjectName(u"Series")
self.Series.setMinimumSize(QSize(312, 35))
self.Series.setMaximumSize(QSize(312, 35))
self.gridLayout.addWidget(self.Series, 11, 0, 1, 2)
self.Continue = QPushButton(self.centralwidget)
self.Continue.setObjectName(u"Continue")
self.Continue.setMinimumSize(QSize(312, 35))
self.Continue.setMaximumSize(QSize(312, 35))
self.gridLayout.addWidget(self.Continue, 14, 0, 1, 2)
self.line_3 = QFrame(self.centralwidget)
self.line_3.setObjectName(u"line_3")
self.line_3.setFrameShape(QFrame.Shape.HLine)
self.line_3.setFrameShadow(QFrame.Shadow.Sunken)
self.gridLayout.addWidget(self.line_3, 13, 0, 1, 2)
self.Patronymic = QLineEdit(self.centralwidget)
self.Patronymic.setObjectName(u"Patronymic")
self.Patronymic.setMinimumSize(QSize(312, 35))
self.Patronymic.setMaximumSize(QSize(312, 35))
self.gridLayout.addWidget(self.Patronymic, 7, 0, 1, 2)
self.Surname = QLineEdit(self.centralwidget)
self.Surname.setObjectName(u"Surname")
self.Surname.setMinimumSize(QSize(312, 35))
self.Surname.setMaximumSize(QSize(312, 35))
self.gridLayout.addWidget(self.Surname, 6, 0, 1, 2)
self.Number = QLineEdit(self.centralwidget)
self.Number.setObjectName(u"Number")
self.Number.setMinimumSize(QSize(312, 35))
self.Number.setMaximumSize(QSize(312, 35))
self.gridLayout.addWidget(self.Number, 12, 0, 1, 2)
OST_authorization.setCentralWidget(self.centralwidget)
self.menubar = QMenuBar(OST_authorization)
self.menubar.setObjectName(u"menubar")
self.menubar.setGeometry(QRect(0, 0, 330, 22))
OST_authorization.setMenuBar(self.menubar)
self.statusbar = QStatusBar(OST_authorization)
self.statusbar.setObjectName(u"statusbar")
OST_authorization.setStatusBar(self.statusbar)
self.retranslateUi(OST_authorization)
QMetaObject.connectSlotsByName(OST_authorization)
def retranslateUi(self, OST_authorization):
OST_authorization.setWindowTitle(QCoreApplication.translate("OST_authorization", u"OST - (\u0434\u0435\u043c\u043e \u0432\u0435\u0440\u0441\u0438\u044f)", None))
self.Name.setPlaceholderText(QCoreApplication.translate("OST_authorization", u"\u0418\u043c\u044f", None))
self.AuthorizationLable.setText(QCoreApplication.translate("OST_authorization", u"<html><head/><body><p><span style=\" font-size:12pt;\">\u0410\u0432\u0442\u043e\u0440\u0438\u0437\u0430\u0446\u0438\u044f</span></p></body></html>", None))
self.Class.setPlaceholderText(QCoreApplication.translate("OST_authorization", u"\u041d\u043e\u043c\u0435\u0440 \u0438 \u0431\u0443\u043a\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430", None))
self.Series.setPlaceholderText(QCoreApplication.translate("OST_authorization", u"\u0421\u0435\u0440\u0438\u044f", None))
self.Continue.setText(QCoreApplication.translate("OST_authorization", u"\u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c", None))
self.Patronymic.setPlaceholderText(QCoreApplication.translate("OST_authorization", u"\u041e\u0442\u0447\u0435\u0441\u0442\u0432\u043e (\u043f\u0440\u0438 \u043d\u0430\u043b\u0438\u0447\u0438\u0438)", None))
self.Surname.setPlaceholderText(QCoreApplication.translate("OST_authorization", u"\u0424\u0430\u043c\u0438\u043b\u0438\u044f", None))
self.Number.setPlaceholderText(QCoreApplication.translate("OST_authorization", u"\u041d\u043e\u043c\u0435\u0440", None))
# ----------------> vvvvvvvvvvv <-------------------------------------
class Authorization(QMainWindow): # - QWidget
def __init__(self):
super().__init__()
self.ui = Ui_OST_authorization()
self.ui.setupUi(self)
self.ui.Continue.clicked.connect(
lambda: print(self.ui.Continue.text()))
# или так:
#class Authorization(QMainWindow, Ui_OST_authorization):
# def __init__(self):
# super().__init__()
# self.setupUi(self)
# self.Continue.clicked.connect(
# lambda: print(self.Continue.text()))
#- self.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
w = Authorization()
w.show() # +
sys.exit(app.exec())