From dfc31b33b608c4f38629924d5225ab7c36b6a1b3 Mon Sep 17 00:00:00 2001
From: Almar Klein <almar@almarklein.org>
Date: Thu, 7 Nov 2024 10:26:19 +0100
Subject: [PATCH] Fix use-case where canvas misses requests for a new draw

---
 rendercanvas/_loop.py | 2 +-
 rendercanvas/qt.py    | 9 +++++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/rendercanvas/_loop.py b/rendercanvas/_loop.py
index 1e17e41..941e8a4 100644
--- a/rendercanvas/_loop.py
+++ b/rendercanvas/_loop.py
@@ -360,7 +360,7 @@ def _schedule_next_tick(self):
             return
 
         # Determine delay
-        if self._mode == "fastest":
+        if self._mode == "fastest" or self._max_fps <= 0:
             delay = 0
         else:
             delay = 1 / self._max_fps
diff --git a/rendercanvas/qt.py b/rendercanvas/qt.py
index 1dfbf9a..1071a4a 100644
--- a/rendercanvas/qt.py
+++ b/rendercanvas/qt.py
@@ -182,6 +182,11 @@ def paintEngine(self):  # noqa: N802 - this is a Qt method
     def paintEvent(self, event):  # noqa: N802 - this is a Qt method
         self._draw_frame_and_present()
 
+    def update(self):
+        # Bypass Qt's mechanics and request a draw so that the scheduling mechanics work as intended.
+        # Eventually this will call _request_draw().
+        self.request_draw()
+
     # Methods that we add for BaseRenderCanvas (snake_case)
 
     def _request_draw(self):
@@ -490,6 +495,10 @@ def __init__(self, *, size=None, title=None, **kwargs):
 
     # Qt methods
 
+    def update(self):
+        self._subwidget.request_draw()
+        super().update()
+
     def closeEvent(self, event):  # noqa: N802
         self._subwidget._is_closed = True
         self.submit_event({"event_type": "close"})