2025-10-31 18:52:31 +08:00
|
|
|
|
from PySide6.QtWidgets import (QApplication, QVBoxLayout, QPushButton, QDialog)
|
|
|
|
|
|
from PySide6.QtGui import QPixmap, QFont, QIcon, QPainter
|
|
|
|
|
|
from PySide6.QtCore import Qt, Signal
|
|
|
|
|
|
from PySide6.QtCore import Qt, Signal, QPropertyAnimation, QEasingCurve, QRect
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
import resources.resources_rc
|
2025-11-01 16:13:14 +08:00
|
|
|
|
from utils.image_paths import ImagePaths
|
2025-10-31 18:52:31 +08:00
|
|
|
|
|
|
|
|
|
|
class CustomButton(QPushButton):
|
|
|
|
|
|
def __init__(self, text, normal_icon, active_icon, parent=None):
|
|
|
|
|
|
super().__init__(text, parent)
|
|
|
|
|
|
self.normal_icon = normal_icon
|
|
|
|
|
|
self.active_icon = active_icon
|
|
|
|
|
|
self.setFixedSize(147, 36)
|
|
|
|
|
|
self.setCursor(Qt.PointingHandCursor)
|
|
|
|
|
|
self.update_icon(self.normal_icon)
|
|
|
|
|
|
self.setFont(QFont("", 17))
|
|
|
|
|
|
self.setStyleSheet("""
|
|
|
|
|
|
QPushButton {
|
|
|
|
|
|
color: #16ffff;
|
|
|
|
|
|
background: none;
|
|
|
|
|
|
outline: none;
|
|
|
|
|
|
border: none;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
background-color: transparent;
|
|
|
|
|
|
font-weight: Bold;
|
|
|
|
|
|
}
|
|
|
|
|
|
QPushButton:hover {
|
|
|
|
|
|
color: #001c83;
|
|
|
|
|
|
background-color: #16ffff;
|
|
|
|
|
|
background-repeat: no-repeat;
|
|
|
|
|
|
outline: none;
|
|
|
|
|
|
border: none;
|
|
|
|
|
|
}
|
|
|
|
|
|
""")
|
|
|
|
|
|
|
|
|
|
|
|
def update_icon(self, icon_path):
|
|
|
|
|
|
pixmap = QPixmap(icon_path)
|
|
|
|
|
|
if not pixmap.isNull():
|
|
|
|
|
|
scaled_pixmap = pixmap.scaled(24, 24, Qt.KeepAspectRatio, Qt.SmoothTransformation)
|
|
|
|
|
|
self.setIcon(QIcon(scaled_pixmap))
|
|
|
|
|
|
self.setIconSize(scaled_pixmap.size())
|
|
|
|
|
|
else:
|
|
|
|
|
|
self.setIcon(QIcon())
|
|
|
|
|
|
|
|
|
|
|
|
def enterEvent(self, event):
|
|
|
|
|
|
self.update_icon(self.active_icon)
|
|
|
|
|
|
super().enterEvent(event)
|
|
|
|
|
|
|
|
|
|
|
|
def leaveEvent(self, event):
|
|
|
|
|
|
self.update_icon(self.normal_icon)
|
|
|
|
|
|
super().leaveEvent(event)
|
|
|
|
|
|
|
|
|
|
|
|
class SystemCenterDialog(QDialog):
|
|
|
|
|
|
# 定义三个信号,对应三个按钮的点击事件
|
|
|
|
|
|
sys_setting_clicked = Signal() # 系统设置点击信号
|
|
|
|
|
|
data_center_clicked = Signal() # 数据中心点击信号
|
|
|
|
|
|
user_center_clicked = Signal() # 用户中心点击信号
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
|
|
super().__init__(parent)
|
2025-11-07 15:45:54 +08:00
|
|
|
|
self._init_ui()
|
2025-10-31 18:52:31 +08:00
|
|
|
|
|
2025-11-07 15:45:54 +08:00
|
|
|
|
def _init_ui(self):
|
2025-10-31 18:52:31 +08:00
|
|
|
|
# 弹窗基础设置
|
|
|
|
|
|
self.setWindowTitle("系统中心")
|
|
|
|
|
|
self.setWindowFlags(Qt.FramelessWindowHint) # 隐藏默认边框
|
|
|
|
|
|
self.setWindowOpacity(0.0) # 初始状态为完全透明,实现动画效果
|
2025-11-13 09:37:41 +08:00
|
|
|
|
self.hide() # 初始状态为隐藏 (必须)
|
2025-10-31 18:52:31 +08:00
|
|
|
|
|
|
|
|
|
|
# 加载背景图
|
2025-11-01 16:13:14 +08:00
|
|
|
|
self.background = QPixmap(ImagePaths.SYSTEM_CENTER_POPUP_BG)
|
2025-10-31 18:52:31 +08:00
|
|
|
|
if self.background.isNull():
|
|
|
|
|
|
print("警告:系统中心弹窗背景.png 加载失败!")
|
|
|
|
|
|
self.setFixedSize(220, 200)
|
|
|
|
|
|
else:
|
|
|
|
|
|
self.setFixedSize(self.background.size())
|
|
|
|
|
|
|
|
|
|
|
|
# 主布局
|
|
|
|
|
|
main_layout = QVBoxLayout(self)
|
|
|
|
|
|
main_layout.setContentsMargins(0, 0, 0, 6)
|
|
|
|
|
|
main_layout.setSpacing(0)
|
|
|
|
|
|
main_layout.setAlignment(Qt.AlignCenter)
|
|
|
|
|
|
|
|
|
|
|
|
# 创建按钮并绑定信号发射
|
2025-11-01 16:13:14 +08:00
|
|
|
|
self.sys_btn = CustomButton("系统设置", ImagePaths.SYSTEM_SETTING_BG1, ImagePaths.SYSTEM_SETTING_BG2)
|
|
|
|
|
|
self.data_btn = CustomButton("数据中心", ImagePaths.SYSTEM_DATA_CENTER_BG1, ImagePaths.SYSTEM_DATA_CENTER_BG2)
|
|
|
|
|
|
self.user_btn = CustomButton("用户中心", ImagePaths.SYSTEM_USER_CENTER_BG1, ImagePaths.SYSTEM_USER_CENTER_BG2)
|
2025-10-31 18:52:31 +08:00
|
|
|
|
|
|
|
|
|
|
# 按钮点击 → 发射对应信号(dialog不处理业务逻辑,只传递事件)
|
|
|
|
|
|
self.sys_btn.clicked.connect(self.sys_setting_clicked.emit)
|
|
|
|
|
|
self.data_btn.clicked.connect(self.data_center_clicked.emit)
|
|
|
|
|
|
self.user_btn.clicked.connect(self.user_center_clicked.emit)
|
|
|
|
|
|
|
|
|
|
|
|
main_layout.addWidget(self.sys_btn)
|
|
|
|
|
|
main_layout.addWidget(self.data_btn)
|
|
|
|
|
|
main_layout.addWidget(self.user_btn)
|
|
|
|
|
|
|
|
|
|
|
|
def paintEvent(self, event):
|
|
|
|
|
|
painter = QPainter(self)
|
|
|
|
|
|
painter.drawPixmap(self.rect(), self.background)
|
|
|
|
|
|
super().paintEvent(event)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
|
|
dialog = SystemCenterDialog()
|
|
|
|
|
|
# 测试信号(实际业务在控制器中绑定)
|
|
|
|
|
|
dialog.sys_setting_clicked.connect(lambda: print("系统设置被点击"))
|
|
|
|
|
|
dialog.show()
|
|
|
|
|
|
sys.exit(app.exec())
|