77 lines
2.6 KiB
Python
77 lines
2.6 KiB
Python
from PySide6.QtWidgets import QApplication, QPushButton, QHBoxLayout, QWidget
|
||
from PySide6.QtGui import QIcon
|
||
from PySide6.QtCore import QSize, Qt
|
||
import sys
|
||
|
||
import resources.resources_rc
|
||
from utils.image_paths import ImagePaths
|
||
|
||
class SystemButtonWidget(QWidget):
|
||
def __init__(self):
|
||
super().__init__()
|
||
self.initUI()
|
||
|
||
def initUI(self):
|
||
# 创建水平布局,并设置按钮间距为27px
|
||
layout = QHBoxLayout()
|
||
layout.setSpacing(27) # 按钮之间的间距
|
||
layout.setContentsMargins(6, 6, 6, 6) # 布局边缘留白
|
||
|
||
self.setWindowTitle("系统按钮")
|
||
self.setFixedSize(776, 65) # widget大小
|
||
|
||
# 按钮样式表
|
||
button_style = """
|
||
QPushButton {
|
||
width: 120px; /* 宽120px */
|
||
height: 40px; /* 高40px */
|
||
background-color: #7f95bf; /* 平时颜色 */
|
||
color: white; /* 文字颜色(白色更清晰) */
|
||
font-size: 20px; /* 字号20px */
|
||
border: none; /* 去掉默认边框 */
|
||
border-radius: 4px; /* 轻微圆角(可选,更美观) */
|
||
}
|
||
QPushButton:hover {
|
||
background-color: #2573d3; /* 鼠标悬停颜色 */
|
||
}
|
||
QPushButton:pressed {
|
||
background-color: #1d5cb8; /* 点击时颜色(可选增强) */
|
||
}
|
||
"""
|
||
|
||
# 创建按钮列表(图标+文字)
|
||
# 注意:需要替换为实际的图片路径
|
||
buttons_info = [
|
||
("系统启动", ImagePaths.SYSTEM_START),
|
||
("系统停止", ImagePaths.SYSTEM_STOP),
|
||
("系统复位", ImagePaths.SYSTEM_RESET),
|
||
("AI检测", ImagePaths.AI_DETECT),
|
||
("任务刷新", ImagePaths.TASK_REFRESH)
|
||
]
|
||
|
||
# 存放按钮控件的字典
|
||
self.buttons = dict()
|
||
|
||
for text, icon_path in buttons_info:
|
||
btn = QPushButton(text)
|
||
# 设置图标
|
||
icon = QIcon(icon_path)
|
||
btn.setIcon(icon)
|
||
btn.setIconSize(QSize(24, 24)) # 图标尺寸(与按钮比例协调)
|
||
# 设置固定尺寸(确保宽高生效)
|
||
btn.setFixedSize(120, 40)
|
||
# 应用样式
|
||
btn.setStyleSheet(button_style)
|
||
# 添加到布局
|
||
layout.addWidget(btn)
|
||
|
||
self.buttons[text] = btn
|
||
|
||
self.setLayout(layout)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
app = QApplication(sys.argv)
|
||
window = SystemButtonWidget()
|
||
window.show()
|
||
sys.exit(app.exec()) |