You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.5 KiB
Python

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from controllers.caller_main import CallerMain
from views.Ui_login import Ui_win_Login
# login界面controller类
# 需要继承QWidget 如果是主窗体需要继承QMainWindow
class Login(QWidget):
def __init__(self):
# 这句一定要调用父类构造函数
super().__init__()
# 动态加载UI文件
self.ui = Ui_win_Login()
self.ui.setupUi(self)
self.setWindowFlag(Qt.FramelessWindowHint) # 去除边框
self.setAttribute(Qt.WA_TranslucentBackground) # 将界面属性设置为半透明
# 设定一个阴影半径为10 颜色为#444 定位为00
self.shadow = QGraphicsDropShadowEffect()
self.shadow.setBlurRadius(10)
self.shadow.setColor(QColor('#444'))
self.shadow.setOffset(0, 0)
self.ui.f_login_main.setGraphicsEffect(self.shadow)
# 注册登录按钮事件
self.ui.btn_login.clicked.connect(self.login_action)
# 注册关闭程序按钮事件
self.ui.btn_close.clicked.connect(self.exit_action)
# 注册最小化窗口按钮事件
self.ui.btn_min.clicked.connect(self.min_action)
# 登录按钮事件
def login_action(self):
# 创建窗口选择界面对象
self.callerMain = CallerMain()
# 显示窗口选择界面
self.callerMain.show()
# 关闭登录界面
self.close()
# print('login success')
# 关闭按钮事件
def exit_action():
app = QApplication.instance()
app.quit()
# 最小化事件
def min_action(self):
self.showMinimized()
# 重写鼠标按下事件 左键按下时获取鼠标坐标,按下右键取消
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.m_flag = True
self.m_Position = event.globalPos() - self.pos()
event.accept()
elif event.button() == Qt.RightButton:
self.m_flag = False
# 重写鼠标移动事件 在按下左键移动是根据坐标移动界面
def mouseMoveEvent(self, QMouseEvent):
if Qt.LeftButton and self.m_flag and self.ui.f_title.underMouse():
self.move(QMouseEvent.globalPos() - self.m_Position)
QMouseEvent.accept()
# 重写鼠标释放事件 当鼠标按键释放时 取消移动
def mouseReleaseEvent(self, QMouseEvent):
self.m_flag = False