箭头改成圆形

main
risingLee 2026-02-25 15:46:39 +08:00
parent c21089e8ea
commit 73fd35edb8
1 changed files with 8 additions and 19 deletions

27
main.py
View File

@ -682,7 +682,7 @@ class ArrowItem(DashboardItem):
) )
def paint(self, painter, option, widget=None): def paint(self, painter, option, widget=None):
"""编辑模式:画虚线边框 + 箭头;展示模式:只画箭头,不画边框。""" """编辑模式:画虚线边框 + 两端圆点线段;展示模式:只画线段和圆点,不画边框。"""
r = self.rect() r = self.rect()
if r.width() <= 1 or r.height() <= 1: if r.width() <= 1 or r.height() <= 1:
return return
@ -697,7 +697,7 @@ class ArrowItem(DashboardItem):
painter.setBrush(Qt.BrushStyle.NoBrush) painter.setBrush(Qt.BrushStyle.NoBrush)
painter.drawRect(r) painter.drawRect(r)
# 画箭头(在 rect 内按角度绘制;不使用 item rotation避免影响边界/磁吸/约束) # 画线段和两端圆点(在 rect 内按角度绘制;不使用 item rotation避免影响边界/磁吸/约束)
arrow_color = QColor(self._color) arrow_color = QColor(self._color)
pen = QPen(arrow_color, self._width) pen = QPen(arrow_color, self._width)
pen.setCapStyle(Qt.PenCapStyle.RoundCap) pen.setCapStyle(Qt.PenCapStyle.RoundCap)
@ -719,26 +719,15 @@ class ArrowItem(DashboardItem):
t = max(5.0, min(t_max_x, t_max_y)) t = max(5.0, min(t_max_x, t_max_y))
start = QPointF(cx - vx * t, cy - vy * t) start = QPointF(cx - vx * t, cy - vy * t)
end = QPointF(cx + vx * t, cy + vy * t) end = QPointF(cx + vx * t, cy + vy * t)
# 绘制连接线
painter.drawLine(start, end) 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)) w = float(max(1, self._width))
arrow_len = max(8.0, min(28.0, 6.0 + w * 3.0)) dot_radius = max(4.0, min(12.0, 3.0 + w * 1.2)) # 圆点半径随线宽缩放
half_width = max(4.0, min(14.0, 3.5 + w * 1.6)) painter.drawEllipse(start, dot_radius, dot_radius)
back = QPointF(end.x() - ux * arrow_len, end.y() - uy * arrow_len) painter.drawEllipse(end, dot_radius, dot_radius)
# 垂直方向
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])
class WebItem(DashboardItem): class WebItem(DashboardItem):