增加重量更新显示,hopper_controller 提供了料斗模块的数据接口

This commit is contained in:
2025-11-06 10:55:29 +08:00
parent 84382b0cc0
commit d2603cec4d
16 changed files with 278 additions and 94 deletions

View File

@ -74,12 +74,47 @@ class ConveyorSystemWidget(QWidget):
inner_img = ImagePaths.HOPPER2
inner_pixmap = QPixmap(inner_img)
if not inner_pixmap.isNull():
upper_inner_label = QLabel(upper_bg_widget)
upper_inner_label.setPixmap(inner_pixmap)
upper_inner_label.setFixedSize(inner_pixmap.width(), inner_pixmap.height())
upper_inner_label.move(14, 9) # 保持原位置
self.upper_inner_label = QLabel(upper_bg_widget)
self.upper_inner_label.setPixmap(inner_pixmap)
self.upper_inner_label.setFixedSize(inner_pixmap.width(), inner_pixmap.height())
self.upper_inner_label.setScaledContents(False)
self.upper_inner_label.setStyleSheet("background: none;")
self.upper_inner_label.move(14, 9)
self.upper_inner_label.setAlignment(Qt.AlignBottom)
return group
def _update_upper_inner_height(self, total_weight, current_weight: float):
"""根据当前重量占比, 更新upper_inner_label的高度, 实现动态进度的效果"""
# 1、处理边界值超过总重量按100%低于0按0%
clamped_weight = max(0.0, min(current_weight, total_weight))
# 2、计算占比0~1之间
weight_ratio = clamped_weight / (total_weight * 1.0)
# 3、根据占比计算实际高度
inner_img_height = 100 # 内部的料斗阴影的高度为100px
target_height = int(weight_ratio * inner_img_height)
# print("target_height: ", target_height)
# 4、设置标签高度动态变化
self.upper_inner_label.setFixedHeight(target_height)
# 5、计算标签位置确保标签底部与父容器底部对齐
container_bottom = 117 # 容器的高固定为了 117px (背景图片"料斗1"的高)
label_y = container_bottom - target_height - 8 # 标签顶部y坐标 (减去底部8px)
self.upper_inner_label.move(14, label_y) # x固定y动态计算
# print("label_y", label_y)
# 6、强制刷新UI确保立即显示变化
self.upper_inner_label.update()
def setConveyorHopperWeight(self, weight:float):
# 1、更新传送带中的 上料斗内部进度显示
# 假设上料斗装满之后,总的重量为 5100kg
total_weight = 5100
self._update_upper_inner_height(total_weight, weight)
def create_conveyor(self):
"""创建传送带组件包含左右齿轮group容器背景为传送带图片"""