界面修改以及显示

This commit is contained in:
2025-10-31 18:52:31 +08:00
parent bd0815d0e7
commit 290324b5e4
93 changed files with 17169 additions and 12529 deletions

188
view/widgets/task_widget.py Normal file
View File

@ -0,0 +1,188 @@
from PySide6.QtWidgets import (QWidget, QVBoxLayout, QHBoxLayout, QLabel,
QPushButton, QMessageBox, QApplication)
from PySide6.QtCore import Qt
from PySide6.QtGui import QPainter, QPixmap, QFont
import sys
import resources.resources_rc
# 任务控件,如:管片任务、派单任务
class TaskWidget(QWidget):
def __init__(self, taskTitle:str, parent=None):
super().__init__(parent)
# 设置Widget大小与背景图一致
self.bg_pixmap = QPixmap(":/icons/images/任务信息背景1.png")
self.setFixedSize(self.bg_pixmap.size())
# 主布局(垂直)
self.main_layout = QVBoxLayout(self)
self.main_layout.setContentsMargins(0, 0, 0, 6)
self.main_layout.setSpacing(0)
# 任务标题
title_label = QLabel(taskTitle, self)
title_label.setStyleSheet("font-size: 24px; color: #16ffff;padding-top:4px;")
title_label.setAlignment(Qt.AlignCenter)
self.main_layout.addWidget(title_label, alignment=Qt.AlignTop)
# 标题字体设置
# title_font = title_label.font()
title_font = QFont("Microsoft YaHei")
title_font.setLetterSpacing(QFont.AbsoluteSpacing, 3) # 字间距3px
title_font.setWeight(QFont.DemiBold)
title_label.setFont(title_font)
# 用字典存储每个任务的可修改控件(键:任务名,值:控件字典)
self.task_controls = {} # 结构:{"task1": {"volume_label": xxx, "time_label": xxx, ...}, ...}
# 三条任务条目
self._add_task("task1", "SHRB1-3", ":/icons/images/任务矩形1.png")
self._add_task("task2", "SHRB2-3", ":/icons/images/任务矩形2.png")
self._add_task("task3", "SHRB1-3", ":/icons/images/任务矩形3.png")
def paintEvent(self, event):
"""绘制背景图片"""
painter = QPainter(self)
painter.drawPixmap(self.rect(), self.bg_pixmap)
super().paintEvent(event)
def _add_task(self, task_name, task_id, status_icon):
"添加相应的任务条目到布局,同时将其相应的控件存入字典"
# 1、创建任务条目以及相应的控件字典
item_widget, controls = self._create_task_item(task_name, task_id, status_icon)
# 2、将控件字典存入 相应的 任务条目字典
self.task_controls[task_name] = controls
# 3、将任务条目添加到主布局
self.main_layout.addWidget(item_widget, alignment=Qt.AlignTop)
def _create_task_item(self, task_name, task_id, status_icon):
"""创建单条任务条目, 返回任务条目和控件字典"""
item_widget = QWidget()
item_layout = QVBoxLayout(item_widget)
item_layout.setContentsMargins(9, 6, 9, 8)
item_layout.setSpacing(0)
# 相应的 任务条目的控件字典
controls = {} # {"volume_label": ..., "time_label": ..., ...}
# 水平布局1选择按钮 + 任务名 + 详情按钮
row1_layout = QHBoxLayout()
# 任务选择按钮
select_btn = QPushButton()
select_btn.setFixedSize(14, 14)
select_btn.setCursor(Qt.PointingHandCursor)
select_btn.setStyleSheet("""
QPushButton {
background-image: url(:/icons/images/任务信息选择按钮1.png);
border: none;
}
QPushButton:checked {
background-image: url(:/icons/images/任务信息选择按钮2.png);
}
""")
select_btn.setCheckable(True)
controls["select_btn"] = select_btn
row1_layout.addWidget(select_btn)
# 任务编号
task_id_label = QLabel(task_id)
task_id_label.setStyleSheet("font-size: 18px; color: #16ffff;padding-left: 6px;")
controls["task_id_label"] = task_id_label
row1_layout.addWidget(task_id_label)
# 详情按钮
detail_btn = QPushButton()
detail_btn.setText("详情")
detail_btn.setFixedSize(46, 26)
detail_btn.setCursor(Qt.PointingHandCursor)
detail_btn.setStyleSheet("""
QPushButton {
background-image: url(:/icons/images/任务信息详情按钮1.png);
border: none;
color: #3bfff8;
font-size: 16px;
}
QPushButton:hover {
background-image: url(:/icons/images/任务信息详情按钮2.png);
color: #001c83;
font-size: 16px;
}
""")
detail_btn.clicked.connect(lambda: self._show_detail_dialog(task_name)) # 详情按钮槽函数
controls["detail_btn"] = detail_btn
row1_layout.addWidget(detail_btn)
item_layout.addLayout(row1_layout)
# 水平布局2方量 + / + 时间 + 状态图标
row2_layout = QHBoxLayout()
# 方量标签
volume_label = QLabel("方量 200")
volume_label.setStyleSheet("color: #a1c1d7; font-size: 14px;padding-left: 19px;")
controls["volume_label"] = volume_label
row2_layout.addWidget(volume_label)
# 分隔标签
sep_label = QLabel("/")
sep_label.setStyleSheet("color: #a1c1d7;")
row2_layout.addWidget(sep_label, alignment=Qt.AlignCenter)
# 时间标签
time_label = QLabel("03:22PM")
time_label.setStyleSheet("color: #a1c1d7; font-size: 14px;")
controls["time_label"] = time_label
row2_layout.addWidget(time_label)
# 状态标签
status_icon_label = QLabel()
status_icon_label.setPixmap(QPixmap(status_icon))
controls["status_icon_label"] = status_icon_label
row2_layout.addWidget(status_icon_label, alignment=Qt.AlignRight)
item_layout.addLayout(row2_layout)
# 分隔线
item_layout.setSpacing(5)
separator = QLabel()
separator.setPixmap(QPixmap(":/icons/images/任务信息分隔.png"))
separator.setFixedSize(196, 1)
item_layout.addWidget(separator)
return item_widget, controls # 返回任务条目 以及 相应的控件
def _show_detail_dialog(self, task_name):
"""显示任务详情弹窗"""
QMessageBox.information(self, "任务详情", f"任务 {task_name} 的详细信息...")
# --------------------------
# 对外接口:修改任务属性
# 三个任务条目对应的任务名task_name分别为 task1、task2、task3
# --------------------------
def set_task_volume(self, task_name:str, volume: float):
"""修改指定任务的方量, 传入具体的方量值,如: 200.0"""
if task_name in self.task_controls:
volume_label = self.task_controls[task_name]["volume_label"]
volume_label.setText(f"方量 {volume}")
def set_task_time(self, task_name:str, time_str: str):
"""修改指定任务的时间, 传入对应格式的时间,如: 03:22PM"""
if task_name in self.task_controls:
time_label = self.task_controls[task_name]["time_label"]
time_label.setText(time_str)
def set_task_id(self, task_name:str, new_id: str):
"""修改指定任务的编号, 如: SHRB2-3"""
if task_name in self.task_controls:
task_id_label = self.task_controls[task_name]["task_id_label"]
task_id_label.setText(new_id)
if __name__ == "__main__":
app = QApplication(sys.argv)
widget = TaskWidget("管片任务")
# 示例修改task2的方量为300测试用
widget.set_task_volume("task2", 300)
# 示例修改task1的时间为04:50PM测试用
widget.set_task_time("task1", "04:50PM")
widget.show()
sys.exit(app.exec())