PySide6 之登录界面设计
一、效果图
二、示例代码
from PySide6.QtWidgets import QApplication, QWidget from PySide6.QtCore import Qt, Slot, QPoint, QPropertyAnimation, QEasingCurve from PySide6.QtGui import QColor from views.login_ui import Ui_LoginForm import sys class Login(QWidget, Ui_LoginForm): drag_pos = QPoint() animation = None def __init__(self): super().__init__() self.setWindowFlags(Qt.WindowType.FramelessWindowHint) self.setAttribute(Qt.WidgetAttribute.WA_TranslucentBackground) self.setupUi(self) @Slot() def on_pushButton_close_clicked(self): self.close() def paintEvent(self, event): if not self.animation: self.animation = QPropertyAnimation(self) self.animation.setTargetObject(self) self.animation.setPropertyName(b"windowOpacity") # 设置初动画始值 self.animation.setStartValue(0) # 设置动画结束值 self.animation.setEndValue(1) # 设置动画线性 self.animation.setEasingCurve(QEasingCurve.Linear) # 设置动画时长 self.animation.setDuration(500) # 设置循环次数 如果是-1则无限循环 self.animation.setLoopCount(1) self.animation.start() event.accept() def mousePressEvent(self, event): if event.buttons() == Qt.MouseButton.LeftButton: self.drag_pos = event.globalPos() - self.frameGeometry().topLeft() event.accept() def mouseMoveEvent(self, event): if event.buttons() == Qt.MouseButton.LeftButton: self.move(event.globalPos() - self.drag_pos) event.accept() if __name__ == '__main__': app = QApplication(sys.argv) d = Login() d.show() sys.exit(app.exec())