加载 ui 文件时 Pyqt 建议不可用
我正在使用 Qt Designer 来设计 GUI,但是当我在代码中加载 Ui
文件时。
问题1
我无法获得代码建议,例如我的GUI中具有哪些属性等。
上述解决方案
我没有加载Ui
文件,而是使用pyuic5 -o register_ui.py Register.ui
将其转换为.py
,这样我得到:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Register.ui'
#
# Created by: PyQt5 UI code generator 5.14.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_RegisterationWin(object):
def setupUi(self, RegisterationWin):
RegisterationWin.setObjectName("RegisterationWin")
RegisterationWin.resize(414, 698)
RegisterationWin.setMinimumSize(QtCore.QSize(414, 698))
RegisterationWin.setMaximumSize(QtCore.QSize(746, 806))
RegisterationWin.setWindowOpacity(0.97)
RegisterationWin.setStyleSheet("")
self.centralwidget = QtWidgets.QWidget(RegisterationWin)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.top_frame = QtWidgets.QFrame(self.centralwidget)
self.top_frame.setFrameShape(QtWidgets.QFrame.NoFrame)
self.top_frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.top_frame.setObjectName("top_frame")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.top_frame)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.welcome_lbl = QtWidgets.QLabel(self.top_frame)
font = QtGui.QFont()
font.setPointSize(24)
self.welcome_lbl.setFont(font)
self.welcome_lbl.setObjectName("welcome_lbl")
self.verticalLayout_2.addWidget(self.welcome_lbl, 0, QtCore.Qt.AlignHCenter)
self.label_6 = QtWidgets.QLabel(self.top_frame)
font = QtGui.QFont()
font.setPointSize(19)
font.setBold(True)
font.setWeight(75)
self.label_6.setFont(font)
self.label_6.setObjectName("label_6")
self.verticalLayout_2.addWidget(self.label_6, 0, QtCore.Qt.AlignHCenter)
self.register_lbl = QtWidgets.QLabel(self.top_frame)
font = QtGui.QFont()
font.setPointSize(24)
self.register_lbl.setFont(font)
self.register_lbl.setObjectName("register_lbl")
self.verticalLayout_2.addWidget(self.register_lbl, 0, QtCore.Qt.AlignHCenter)
self.verticalLayout.addWidget(self.top_frame)
self.mid_frame = QtWidgets.QFrame(self.centralwidget)
self.mid_frame.setFrameShape(QtWidgets.QFrame.NoFrame)
self.mid_frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.mid_frame.setObjectName("mid_frame")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.mid_frame)
self.horizontalLayout.setObjectName("horizontalLayout")
self.frame = QtWidgets.QFrame(self.mid_frame)
self.frame.setFrameShape(QtWidgets.QFrame.NoFrame)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.frame)
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.fn_lbl = QtWidgets.QLabel(self.frame)
self.fn_lbl.setObjectName("fn_lbl")
self.verticalLayout_3.addWidget(self.fn_lbl, 0, QtCore.Qt.AlignRight)
self.lb_lbl = QtWidgets.QLabel(self.frame)
self.lb_lbl.setObjectName("lb_lbl")
self.verticalLayout_3.addWidget(self.lb_lbl, 0, QtCore.Qt.AlignRight)
self.dob_lbl = QtWidgets.QLabel(self.frame)
self.dob_lbl.setObjectName("dob_lbl")
self.verticalLayout_3.addWidget(self.dob_lbl, 0, QtCore.Qt.AlignRight)
self.gender_lbl = QtWidgets.QLabel(self.frame)
self.gender_lbl.setObjectName("gender_lbl")
self.verticalLayout_3.addWidget(self.gender_lbl, 0, QtCore.Qt.AlignRight)
self.email_lbl = QtWidgets.QLabel(self.frame)
self.email_lbl.setObjectName("email_lbl")
self.verticalLayout_3.addWidget(self.email_lbl, 0, QtCore.Qt.AlignRight)
self.pass_lbl = QtWidgets.QLabel(self.frame)
self.pass_lbl.setObjectName("pass_lbl")
self.verticalLayout_3.addWidget(self.pass_lbl, 0, QtCore.Qt.AlignRight)
self.confirm_pass_lbl = QtWidgets.QLabel(self.frame)
self.confirm_pass_lbl.setObjectName("confirm_pass_lbl")
self.verticalLayout_3.addWidget(self.confirm_pass_lbl, 0, QtCore.Qt.AlignRight)
self.horizontalLayout.addWidget(self.frame)
self.frame_5 = QtWidgets.QFrame(self.mid_frame)
self.frame_5.setFrameShape(QtWidgets.QFrame.NoFrame)
self.frame_5.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_5.setObjectName("frame_5")
self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.frame_5)
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.fn_input = QtWidgets.QLineEdit(self.frame_5)
self.fn_input.setObjectName("fn_input")
self.verticalLayout_4.addWidget(self.fn_input)
self.ln_input = QtWidgets.QLineEdit(self.frame_5)
self.ln_input.setObjectName("ln_input")
self.verticalLayout_4.addWidget(self.ln_input)
self.dob_input = QtWidgets.QDateEdit(self.frame_5)
self.dob_input.setMaximumDateTime(QtCore.QDateTime(QtCore.QDate(3000, 12, 31), QtCore.QTime(23, 59, 59)))
self.dob_input.setMinimumDateTime(QtCore.QDateTime(QtCore.QDate(1900, 1, 1), QtCore.QTime(0, 0, 0)))
self.dob_input.setCalendarPopup(True)
self.dob_input.setObjectName("dob_input")
self.verticalLayout_4.addWidget(self.dob_input)
self.gender_input = QtWidgets.QComboBox(self.frame_5)
self.gender_input.setObjectName("gender_input")
self.gender_input.addItem("")
self.gender_input.addItem("")
self.gender_input.addItem("")
self.verticalLayout_4.addWidget(self.gender_input)
self.email_input = QtWidgets.QLineEdit(self.frame_5)
self.email_input.setObjectName("email_input")
self.verticalLayout_4.addWidget(self.email_input)
self.pass_input = QtWidgets.QLineEdit(self.frame_5)
self.pass_input.setEchoMode(QtWidgets.QLineEdit.Password)
self.pass_input.setObjectName("pass_input")
self.verticalLayout_4.addWidget(self.pass_input)
self.confirm_pass_input = QtWidgets.QLineEdit(self.frame_5)
self.confirm_pass_input.setEchoMode(QtWidgets.QLineEdit.Password)
self.confirm_pass_input.setObjectName("confirm_pass_input")
self.verticalLayout_4.addWidget(self.confirm_pass_input)
self.horizontalLayout.addWidget(self.frame_5)
self.verticalLayout.addWidget(self.mid_frame)
self.submit_frame = QtWidgets.QFrame(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.submit_frame.sizePolicy().hasHeightForWidth())
self.submit_frame.setSizePolicy(sizePolicy)
self.submit_frame.setMinimumSize(QtCore.QSize(0, 50))
self.submit_frame.setToolTip("")
self.submit_frame.setFrameShape(QtWidgets.QFrame.NoFrame)
self.submit_frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.submit_frame.setObjectName("submit_frame")
self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.submit_frame)
self.verticalLayout_5.setObjectName("verticalLayout_5")
self.submit_button = QtWidgets.QPushButton(self.submit_frame)
self.submit_button.setObjectName("submit_button")
self.verticalLayout_5.addWidget(self.submit_button, 0, QtCore.Qt.AlignRight)
self.verticalLayout.addWidget(self.submit_frame)
self.bottom_frame = QtWidgets.QFrame(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.bottom_frame.sizePolicy().hasHeightForWidth())
self.bottom_frame.setSizePolicy(sizePolicy)
self.bottom_frame.setFrameShape(QtWidgets.QFrame.NoFrame)
self.bottom_frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.bottom_frame.setObjectName("bottom_frame")
self.verticalLayout_6 = QtWidgets.QVBoxLayout(self.bottom_frame)
self.verticalLayout_6.setObjectName("verticalLayout_6")
self.account_lbl = QtWidgets.QLabel(self.bottom_frame)
self.account_lbl.setObjectName("account_lbl")
self.verticalLayout_6.addWidget(self.account_lbl, 0, QtCore.Qt.AlignRight|QtCore.Qt.AlignBottom)
self.signin_lbl = QtWidgets.QLabel(self.bottom_frame)
font = QtGui.QFont()
font.setBold(True)
font.setItalic(True)
font.setUnderline(True)
font.setWeight(75)
self.signin_lbl.setFont(font)
self.signin_lbl.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.signin_lbl.setStyleSheet("color: rgb(52, 101, 164);")
self.signin_lbl.setObjectName("signin_lbl")
self.verticalLayout_6.addWidget(self.signin_lbl, 0, QtCore.Qt.AlignRight|QtCore.Qt.AlignBottom)
self.verticalLayout.addWidget(self.bottom_frame)
RegisterationWin.setCentralWidget(self.centralwidget)
self.retranslateUi(RegisterationWin)
QtCore.QMetaObject.connectSlotsByName(RegisterationWin)
def retranslateUi(self, RegisterationWin):
_translate = QtCore.QCoreApplication.translate
RegisterationWin.setWindowTitle(_translate("RegisterationWin", "Registeration FORM"))
self.welcome_lbl.setText(_translate("RegisterationWin", "Welcome To"))
self.label_6.setText(_translate("RegisterationWin", "Task Management System"))
self.register_lbl.setText(_translate("RegisterationWin", "Registeration Form"))
self.fn_lbl.setText(_translate("RegisterationWin", "First Name"))
self.lb_lbl.setText(_translate("RegisterationWin", "Last Name"))
self.dob_lbl.setText(_translate("RegisterationWin", "DOB"))
self.gender_lbl.setText(_translate("RegisterationWin", "Gender"))
self.email_lbl.setText(_translate("RegisterationWin", "E-mail"))
self.pass_lbl.setText(_translate("RegisterationWin", "Password"))
self.confirm_pass_lbl.setText(_translate("RegisterationWin", "Confirm Password"))
self.dob_input.setDisplayFormat(_translate("RegisterationWin", "dd/MM/yyyy"))
self.gender_input.setItemText(0, _translate("RegisterationWin", "Other"))
self.gender_input.setItemText(1, _translate("RegisterationWin", "Male"))
self.gender_input.setItemText(2, _translate("RegisterationWin", "Female"))
self.submit_button.setText(_translate("RegisterationWin", "Submit"))
self.account_lbl.setText(_translate("RegisterationWin", "Already Have an Account? "))
self.signin_lbl.setText(_translate("RegisterationWin", "SignIn"))
并继承这个类,这样我就不会每次都丢失我的工作我更改设计并重新生成该文件。
from PyQt5 import uic
from PyQt5.QtSql import QSqlQuery
from PyQt5.QtWidgets import QMainWindow
from register_ui import Ui_RegisterationWin
import psycopg2
class RegisterationWinSignals(Ui_RegisterationWin):
def __init__(self, win):
super().__init__()
self.setupUi(win)
self.retranslateUi(win)
self.submit_button.clicked.connect(self.submit_handle)
try:
self.conn = psycopg2.connect(
host='localhost',
dbname='chat_db',
user='postgres',
password='12345678qQ',
port=5432
)
self.cur = self.conn.cursor()
print('connect')
create_query = """
CREATE TABLE IF NOT EXISTS users(
First_Name varchar(70),
Last_Name varchar(70),
dob date,
gender varchar(1),
email varchar(80) PRIMARY KEY,
password varchar(40) NOT NULL
)
"""
self.cur.execute(create_query)
self.conn.commit()
# self.conn.close()
except Exception as e:
print(f"not connect\n{e}")
def submit_handle(self):
fn = self.fn_input.text()
ln = self.ln_input.text()
dob = self.dob_input.text()
email = self.email_input.text()
gender = self.gender_input.currentText()
password = self.pass_input.text()
confirm_password = self.confirm_pass_input.text()
print(f'{fn} {ln}')
print(f'{dob}')
print(f'{email}')
print(f'{gender}')
print(f'{password}')
print(f'{confirm_password}')
if gender == 'Male':
gender = 'M'
elif gender == 'Female:':
gender = 'F'
else:
gender = 'O'
try:
query = f"INSERT INTO users (First_Name, Last_Name, dob, gender, email, password) VALUES(%s, %s, %s, %s, %s, %s); "
values = (fn, ln, dob, gender, email, password)
self.cur.execute(query, values)
self.conn.commit()
except psycopg2.errors.UniqueViolation:
print('already exist')
self.email_input.setStyleSheet("""
border : 1px solid ;
border-color : red;
background-color: rgba(204, 0, 0, 0.2);
""")
self.submit_button.setEnabled(False)
它解决了我之前的问题,但是它导致:
问题2
现在,当我分配信号和处理程序时,它们无法在继承的类中工作。其他一切都工作正常,我收到建议、属性、可以更改属性等。
现在我正在寻找解决我的问题 1 或问题 2 的解决方案
I'm using Qt Designer to design GUI, but when I load Ui
file in my code.
Problem1
I'm unable to get code suggestions like what attributes I have in my GUI etc.
Solution to above
Instead of loading Ui
file, I convert it in .py
with pyuic5 -o register_ui.py Register.ui
, with this I get:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Register.ui'
#
# Created by: PyQt5 UI code generator 5.14.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_RegisterationWin(object):
def setupUi(self, RegisterationWin):
RegisterationWin.setObjectName("RegisterationWin")
RegisterationWin.resize(414, 698)
RegisterationWin.setMinimumSize(QtCore.QSize(414, 698))
RegisterationWin.setMaximumSize(QtCore.QSize(746, 806))
RegisterationWin.setWindowOpacity(0.97)
RegisterationWin.setStyleSheet("")
self.centralwidget = QtWidgets.QWidget(RegisterationWin)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.top_frame = QtWidgets.QFrame(self.centralwidget)
self.top_frame.setFrameShape(QtWidgets.QFrame.NoFrame)
self.top_frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.top_frame.setObjectName("top_frame")
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.top_frame)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.welcome_lbl = QtWidgets.QLabel(self.top_frame)
font = QtGui.QFont()
font.setPointSize(24)
self.welcome_lbl.setFont(font)
self.welcome_lbl.setObjectName("welcome_lbl")
self.verticalLayout_2.addWidget(self.welcome_lbl, 0, QtCore.Qt.AlignHCenter)
self.label_6 = QtWidgets.QLabel(self.top_frame)
font = QtGui.QFont()
font.setPointSize(19)
font.setBold(True)
font.setWeight(75)
self.label_6.setFont(font)
self.label_6.setObjectName("label_6")
self.verticalLayout_2.addWidget(self.label_6, 0, QtCore.Qt.AlignHCenter)
self.register_lbl = QtWidgets.QLabel(self.top_frame)
font = QtGui.QFont()
font.setPointSize(24)
self.register_lbl.setFont(font)
self.register_lbl.setObjectName("register_lbl")
self.verticalLayout_2.addWidget(self.register_lbl, 0, QtCore.Qt.AlignHCenter)
self.verticalLayout.addWidget(self.top_frame)
self.mid_frame = QtWidgets.QFrame(self.centralwidget)
self.mid_frame.setFrameShape(QtWidgets.QFrame.NoFrame)
self.mid_frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.mid_frame.setObjectName("mid_frame")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.mid_frame)
self.horizontalLayout.setObjectName("horizontalLayout")
self.frame = QtWidgets.QFrame(self.mid_frame)
self.frame.setFrameShape(QtWidgets.QFrame.NoFrame)
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame.setObjectName("frame")
self.verticalLayout_3 = QtWidgets.QVBoxLayout(self.frame)
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.fn_lbl = QtWidgets.QLabel(self.frame)
self.fn_lbl.setObjectName("fn_lbl")
self.verticalLayout_3.addWidget(self.fn_lbl, 0, QtCore.Qt.AlignRight)
self.lb_lbl = QtWidgets.QLabel(self.frame)
self.lb_lbl.setObjectName("lb_lbl")
self.verticalLayout_3.addWidget(self.lb_lbl, 0, QtCore.Qt.AlignRight)
self.dob_lbl = QtWidgets.QLabel(self.frame)
self.dob_lbl.setObjectName("dob_lbl")
self.verticalLayout_3.addWidget(self.dob_lbl, 0, QtCore.Qt.AlignRight)
self.gender_lbl = QtWidgets.QLabel(self.frame)
self.gender_lbl.setObjectName("gender_lbl")
self.verticalLayout_3.addWidget(self.gender_lbl, 0, QtCore.Qt.AlignRight)
self.email_lbl = QtWidgets.QLabel(self.frame)
self.email_lbl.setObjectName("email_lbl")
self.verticalLayout_3.addWidget(self.email_lbl, 0, QtCore.Qt.AlignRight)
self.pass_lbl = QtWidgets.QLabel(self.frame)
self.pass_lbl.setObjectName("pass_lbl")
self.verticalLayout_3.addWidget(self.pass_lbl, 0, QtCore.Qt.AlignRight)
self.confirm_pass_lbl = QtWidgets.QLabel(self.frame)
self.confirm_pass_lbl.setObjectName("confirm_pass_lbl")
self.verticalLayout_3.addWidget(self.confirm_pass_lbl, 0, QtCore.Qt.AlignRight)
self.horizontalLayout.addWidget(self.frame)
self.frame_5 = QtWidgets.QFrame(self.mid_frame)
self.frame_5.setFrameShape(QtWidgets.QFrame.NoFrame)
self.frame_5.setFrameShadow(QtWidgets.QFrame.Raised)
self.frame_5.setObjectName("frame_5")
self.verticalLayout_4 = QtWidgets.QVBoxLayout(self.frame_5)
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.fn_input = QtWidgets.QLineEdit(self.frame_5)
self.fn_input.setObjectName("fn_input")
self.verticalLayout_4.addWidget(self.fn_input)
self.ln_input = QtWidgets.QLineEdit(self.frame_5)
self.ln_input.setObjectName("ln_input")
self.verticalLayout_4.addWidget(self.ln_input)
self.dob_input = QtWidgets.QDateEdit(self.frame_5)
self.dob_input.setMaximumDateTime(QtCore.QDateTime(QtCore.QDate(3000, 12, 31), QtCore.QTime(23, 59, 59)))
self.dob_input.setMinimumDateTime(QtCore.QDateTime(QtCore.QDate(1900, 1, 1), QtCore.QTime(0, 0, 0)))
self.dob_input.setCalendarPopup(True)
self.dob_input.setObjectName("dob_input")
self.verticalLayout_4.addWidget(self.dob_input)
self.gender_input = QtWidgets.QComboBox(self.frame_5)
self.gender_input.setObjectName("gender_input")
self.gender_input.addItem("")
self.gender_input.addItem("")
self.gender_input.addItem("")
self.verticalLayout_4.addWidget(self.gender_input)
self.email_input = QtWidgets.QLineEdit(self.frame_5)
self.email_input.setObjectName("email_input")
self.verticalLayout_4.addWidget(self.email_input)
self.pass_input = QtWidgets.QLineEdit(self.frame_5)
self.pass_input.setEchoMode(QtWidgets.QLineEdit.Password)
self.pass_input.setObjectName("pass_input")
self.verticalLayout_4.addWidget(self.pass_input)
self.confirm_pass_input = QtWidgets.QLineEdit(self.frame_5)
self.confirm_pass_input.setEchoMode(QtWidgets.QLineEdit.Password)
self.confirm_pass_input.setObjectName("confirm_pass_input")
self.verticalLayout_4.addWidget(self.confirm_pass_input)
self.horizontalLayout.addWidget(self.frame_5)
self.verticalLayout.addWidget(self.mid_frame)
self.submit_frame = QtWidgets.QFrame(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.submit_frame.sizePolicy().hasHeightForWidth())
self.submit_frame.setSizePolicy(sizePolicy)
self.submit_frame.setMinimumSize(QtCore.QSize(0, 50))
self.submit_frame.setToolTip("")
self.submit_frame.setFrameShape(QtWidgets.QFrame.NoFrame)
self.submit_frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.submit_frame.setObjectName("submit_frame")
self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.submit_frame)
self.verticalLayout_5.setObjectName("verticalLayout_5")
self.submit_button = QtWidgets.QPushButton(self.submit_frame)
self.submit_button.setObjectName("submit_button")
self.verticalLayout_5.addWidget(self.submit_button, 0, QtCore.Qt.AlignRight)
self.verticalLayout.addWidget(self.submit_frame)
self.bottom_frame = QtWidgets.QFrame(self.centralwidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.bottom_frame.sizePolicy().hasHeightForWidth())
self.bottom_frame.setSizePolicy(sizePolicy)
self.bottom_frame.setFrameShape(QtWidgets.QFrame.NoFrame)
self.bottom_frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.bottom_frame.setObjectName("bottom_frame")
self.verticalLayout_6 = QtWidgets.QVBoxLayout(self.bottom_frame)
self.verticalLayout_6.setObjectName("verticalLayout_6")
self.account_lbl = QtWidgets.QLabel(self.bottom_frame)
self.account_lbl.setObjectName("account_lbl")
self.verticalLayout_6.addWidget(self.account_lbl, 0, QtCore.Qt.AlignRight|QtCore.Qt.AlignBottom)
self.signin_lbl = QtWidgets.QLabel(self.bottom_frame)
font = QtGui.QFont()
font.setBold(True)
font.setItalic(True)
font.setUnderline(True)
font.setWeight(75)
self.signin_lbl.setFont(font)
self.signin_lbl.setCursor(QtGui.QCursor(QtCore.Qt.PointingHandCursor))
self.signin_lbl.setStyleSheet("color: rgb(52, 101, 164);")
self.signin_lbl.setObjectName("signin_lbl")
self.verticalLayout_6.addWidget(self.signin_lbl, 0, QtCore.Qt.AlignRight|QtCore.Qt.AlignBottom)
self.verticalLayout.addWidget(self.bottom_frame)
RegisterationWin.setCentralWidget(self.centralwidget)
self.retranslateUi(RegisterationWin)
QtCore.QMetaObject.connectSlotsByName(RegisterationWin)
def retranslateUi(self, RegisterationWin):
_translate = QtCore.QCoreApplication.translate
RegisterationWin.setWindowTitle(_translate("RegisterationWin", "Registeration FORM"))
self.welcome_lbl.setText(_translate("RegisterationWin", "Welcome To"))
self.label_6.setText(_translate("RegisterationWin", "Task Management System"))
self.register_lbl.setText(_translate("RegisterationWin", "Registeration Form"))
self.fn_lbl.setText(_translate("RegisterationWin", "First Name"))
self.lb_lbl.setText(_translate("RegisterationWin", "Last Name"))
self.dob_lbl.setText(_translate("RegisterationWin", "DOB"))
self.gender_lbl.setText(_translate("RegisterationWin", "Gender"))
self.email_lbl.setText(_translate("RegisterationWin", "E-mail"))
self.pass_lbl.setText(_translate("RegisterationWin", "Password"))
self.confirm_pass_lbl.setText(_translate("RegisterationWin", "Confirm Password"))
self.dob_input.setDisplayFormat(_translate("RegisterationWin", "dd/MM/yyyy"))
self.gender_input.setItemText(0, _translate("RegisterationWin", "Other"))
self.gender_input.setItemText(1, _translate("RegisterationWin", "Male"))
self.gender_input.setItemText(2, _translate("RegisterationWin", "Female"))
self.submit_button.setText(_translate("RegisterationWin", "Submit"))
self.account_lbl.setText(_translate("RegisterationWin", "Already Have an Account? "))
self.signin_lbl.setText(_translate("RegisterationWin", "SignIn"))
And inherit this class so that I don't lost my work every time I change the design and regenerate this file.
from PyQt5 import uic
from PyQt5.QtSql import QSqlQuery
from PyQt5.QtWidgets import QMainWindow
from register_ui import Ui_RegisterationWin
import psycopg2
class RegisterationWinSignals(Ui_RegisterationWin):
def __init__(self, win):
super().__init__()
self.setupUi(win)
self.retranslateUi(win)
self.submit_button.clicked.connect(self.submit_handle)
try:
self.conn = psycopg2.connect(
host='localhost',
dbname='chat_db',
user='postgres',
password='12345678qQ',
port=5432
)
self.cur = self.conn.cursor()
print('connect')
create_query = """
CREATE TABLE IF NOT EXISTS users(
First_Name varchar(70),
Last_Name varchar(70),
dob date,
gender varchar(1),
email varchar(80) PRIMARY KEY,
password varchar(40) NOT NULL
)
"""
self.cur.execute(create_query)
self.conn.commit()
# self.conn.close()
except Exception as e:
print(f"not connect\n{e}")
def submit_handle(self):
fn = self.fn_input.text()
ln = self.ln_input.text()
dob = self.dob_input.text()
email = self.email_input.text()
gender = self.gender_input.currentText()
password = self.pass_input.text()
confirm_password = self.confirm_pass_input.text()
print(f'{fn} {ln}')
print(f'{dob}')
print(f'{email}')
print(f'{gender}')
print(f'{password}')
print(f'{confirm_password}')
if gender == 'Male':
gender = 'M'
elif gender == 'Female:':
gender = 'F'
else:
gender = 'O'
try:
query = f"INSERT INTO users (First_Name, Last_Name, dob, gender, email, password) VALUES(%s, %s, %s, %s, %s, %s); "
values = (fn, ln, dob, gender, email, password)
self.cur.execute(query, values)
self.conn.commit()
except psycopg2.errors.UniqueViolation:
print('already exist')
self.email_input.setStyleSheet("""
border : 1px solid ;
border-color : red;
background-color: rgba(204, 0, 0, 0.2);
""")
self.submit_button.setEnabled(False)
It solved my previous problem but It results in:
Problem2
Now signals and handlers unable to work in inherited class when I assign them. Everything else is working fine, I'm getting suggestions, attributes, can change attributes etc.
Now I'm looking for solution that solve my problem1 or problem2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论