箭头改成圆形
parent
c21089e8ea
commit
73fd35edb8
27
main.py
27
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):
|
||||
|
|
|
|||
Loading…
Reference in New Issue