fixed window flashing bug

This commit is contained in:
ykcheungab
2026-09-28 21:17:26 +08:00
parent b8dc5e925b
commit 720bd81031
2 changed files with 194 additions and 1 deletions
@@ -115,6 +115,30 @@ class Mesh3dPanel(QFrame):
#: ``set_domain_latch``). Held until the view exists.
self._domain_latch = None
# Reserve this top-level window's native handle *now*, before the window is
# shown and while no OpenGL widget exists yet.
#
# The view is built on first use, so on a first run — the pane starts on a box,
# which has no 3D scene — the GL widget is created later, while the window is
# already on screen. Creating the first *native* child of a visible window makes
# Qt re-create the window, and Qt does that by hiding it and showing it again:
# measured here as a 250–400 ms disappearance of the whole application, with the
# popup or transient dialog that was open losing its activation and being
# dismissed with it. (``QOpenGLWidget`` sets ``WA_NativeWindow`` on itself.)
# Switching the sensor to ``finger`` in the sensor dialog is exactly that moment,
# which is why it read as "the window closes and reopens and the dialog closes by
# itself".
#
# One zero-sized native child is enough: Qt then already owns a native window
# handle when the 3D widget is added, and no recreation — and so no hide/show —
# happens. It reserves the handle only; it creates no context, no scene and no GL
# import, so the pane stays as lazy as it was. There is no "re-layout" to force
# here: the window was never meant to be hidden at all.
self._native_handle = QWidget(self)
self._native_handle.setObjectName("mesh3dNativeHandle")
self._native_handle.setGeometry(0, 0, 0, 0)
self._native_handle.winId() # creating the handle *is* the point
root = QVBoxLayout(self)
root.setContentsMargins(0, 0, 0, 0)
# The header carries the title and the two actions that belong to *looking*:
@@ -324,7 +348,6 @@ class Mesh3dPanel(QFrame):
if self._loaded or self._source is None or self._view is None:
return
self._loaded = True
view = self._view
if self._loader is None:
self._loader = SceneAssetLoader(self)
self._loader.loaded.connect(self._on_loaded)