fix: end QPainter in finally block to prevent resource leak

This commit is contained in:
2026-04-06 12:11:39 +02:00
parent f0313b10a8
commit ba736fe532
+17 -14
View File
@@ -82,24 +82,27 @@ class TimelineWidget(QWidget):
def paintEvent(self, event): def paintEvent(self, event):
p = QPainter(self) p = QPainter(self)
w, h = self.width(), self.height() try:
w, h = self.width(), self.height()
# Background # Background
p.fillRect(0, 0, w, h, QColor(30, 30, 30)) p.fillRect(0, 0, w, h, QColor(30, 30, 30))
if self._duration <= 0: if self._duration <= 0:
return return
# 8s selection highlight # 8s selection highlight
x_start = int(self._cursor / self._duration * w) x_start = int(self._cursor / self._duration * w)
x_end = int(min(self._cursor + 8.0, self._duration) / self._duration * w) x_end = int(min(self._cursor + 8.0, self._duration) / self._duration * w)
p.fillRect(x_start, 0, x_end - x_start, h, QColor(60, 120, 200, 120)) p.fillRect(x_start, 0, x_end - x_start, h, QColor(60, 120, 200, 120))
# Cursor line # Cursor line
pen = QPen(QColor(255, 200, 0)) pen = QPen(QColor(255, 200, 0))
pen.setWidth(2) pen.setWidth(2)
p.setPen(pen) p.setPen(pen)
p.drawLine(x_start, 0, x_start, h) p.drawLine(x_start, 0, x_start, h)
finally:
p.end()
def mousePressEvent(self, event): def mousePressEvent(self, event):
self._seek(event.position().x()) self._seek(event.position().x())