From 73fd35edb8bf0c55df227d7d09ecf1751c54c4c9 Mon Sep 17 00:00:00 2001 From: risingLee <871066422@qq.com> Date: Wed, 25 Feb 2026 15:46:39 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=AD=E5=A4=B4=E6=94=B9=E6=88=90=E5=9C=86?= =?UTF-8?q?=E5=BD=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/main.py b/main.py index 237d930..51345ff 100644 --- a/main.py +++ b/main.py @@ -682,7 +682,7 @@ class ArrowItem(DashboardItem): ) def paint(self, painter, option, widget=None): - """编辑模式:画虚线边框 + 箭头;展示模式:只画箭头,不画边框。""" + """编辑模式:画虚线边框 + 两端圆点线段;展示模式:只画线段和圆点,不画边框。""" r = self.rect() if r.width() <= 1 or r.height() <= 1: return @@ -697,7 +697,7 @@ class ArrowItem(DashboardItem): painter.setBrush(Qt.BrushStyle.NoBrush) painter.drawRect(r) - # 画箭头(在 rect 内按角度绘制;不使用 item rotation,避免影响边界/磁吸/约束) + # 画线段和两端圆点(在 rect 内按角度绘制;不使用 item rotation,避免影响边界/磁吸/约束) arrow_color = QColor(self._color) pen = QPen(arrow_color, self._width) pen.setCapStyle(Qt.PenCapStyle.RoundCap) @@ -719,26 +719,15 @@ class ArrowItem(DashboardItem): t = max(5.0, min(t_max_x, t_max_y)) start = QPointF(cx - vx * t, cy - vy * t) end = QPointF(cx + vx * t, cy + vy * t) + + # 绘制连接线 painter.drawLine(start, end) - # 箭头三角形 - dx = end.x() - start.x() - dy = end.y() - start.y() - length = math.hypot(dx, dy) or 1.0 - ux, uy = dx / length, dy / length - - # 箭头头部大小随线宽缩放(并限制范围) + # 绘制两端圆点(代替箭头) w = float(max(1, self._width)) - arrow_len = max(8.0, min(28.0, 6.0 + w * 3.0)) - half_width = max(4.0, min(14.0, 3.5 + w * 1.6)) - back = QPointF(end.x() - ux * arrow_len, end.y() - uy * arrow_len) - # 垂直方向 - px, py = -uy, ux - p1 = QPointF(back.x() + px * half_width, back.y() + py * half_width) - p2 = QPointF(back.x() - px * half_width, back.y() - py * half_width) - - # PyQt6 支持直接传入 QPointF 列表,无需 QPolygonF - painter.drawPolygon([end, p1, p2]) + dot_radius = max(4.0, min(12.0, 3.0 + w * 1.2)) # 圆点半径随线宽缩放 + painter.drawEllipse(start, dot_radius, dot_radius) + painter.drawEllipse(end, dot_radius, dot_radius) class WebItem(DashboardItem):