diff --git a/src/gui/widgets/annotation_canvas_widget.py b/src/gui/widgets/annotation_canvas_widget.py index baff64d..94e03cd 100644 --- a/src/gui/widgets/annotation_canvas_widget.py +++ b/src/gui/widgets/annotation_canvas_widget.py @@ -16,8 +16,9 @@ from PySide6.QtGui import ( QKeyEvent, QMouseEvent, QPaintEvent, + QPolygonF, ) -from PySide6.QtCore import Qt, QEvent, Signal, QPoint, QRect +from PySide6.QtCore import Qt, QEvent, Signal, QPoint, QPointF, QRect from typing import Any, Dict, List, Optional, Tuple from src.utils.image import Image, ImageLoadError @@ -496,8 +497,10 @@ class AnnotationCanvasWidget(QWidget): ) painter.setPen(pen) - for (x1, y1), (x2, y2) in zip(polyline[:-1], polyline[1:]): - painter.drawLine(int(x1), int(y1), int(x2), int(y2)) + # Use QPolygonF for efficient polygon rendering (single call vs N-1 calls) + # drawPolygon() automatically closes the shape, ensuring proper visual closure + polygon = QPolygonF([QPointF(x, y) for x, y in polyline]) + painter.drawPolygon(polygon) # Draw bounding boxes (dashed) if enabled if self.show_bboxes and self.original_pixmap is not None and self.bboxes: