From a6dadafe46719813e96ff34fb82e6d7be4724688 Mon Sep 17 00:00:00 2001 From: x01dc Date: Thu, 17 Sep 2026 15:44:23 +0200 Subject: [PATCH] fix(xrayeye): use showEvent() instead of a one-shot timer for control-panel width The previous fix (QTimer.singleShot(0, ...) from _init_ui()) was not reliably late enough in practice -- still reproduced live over a remote desktop session: window opens, image briefly visible, then the control panel's wrong fixed width squeezes it down, recoverable only by moving or resizing the window (which doesn't fix the wrong width itself, just gives the image enough leftover space to look normal despite it). showEvent() is the correct Qt idiom for "run once real geometry is available" -- it fires every time the widget is actually made visible, not just once at construction. Also more robust than a single deferred call: it self-corrects on any later re-show too (e.g. a saved-workspace restore re-applying stale geometry after the fix already ran once). Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Lx3KffiFyyDMKT8vvPENUW --- .../bec_widgets/widgets/xray_eye/x_ray_eye.py | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/csaxs_bec/bec_widgets/widgets/xray_eye/x_ray_eye.py b/csaxs_bec/bec_widgets/widgets/xray_eye/x_ray_eye.py index 6ed7758d..4625c987 100644 --- a/csaxs_bec/bec_widgets/widgets/xray_eye/x_ray_eye.py +++ b/csaxs_bec/bec_widgets/widgets/xray_eye/x_ray_eye.py @@ -581,14 +581,19 @@ class OMNY_XRayEye(BECWidget, QWidget): self.control_panel_layout.addLayout(form) # Fix panel width and allow vertical expansion. The actual width-fixing - # is deferred (see _fix_control_panel_width()) rather than computed + # happens in showEvent() (see _fix_control_panel_width()) rather than # here -- sizeHint() called before the widget has ever been shown/laid # out is unreliable (no real screen geometry yet, fonts not fully # resolved -- worse over a remote desktop session), which froze - # control_panel at a wrong width until the operator manually resized - # the window (forcing Qt to redo layout with correct geometry). + # control_panel at a wrong width until the operator manually moved or + # resized the window (forcing Qt to redo layout with correct + # geometry). A one-shot QTimer.singleShot(0, ...) right here was tried + # first and was NOT reliably late enough (still observed live, over a + # remote desktop session, after that fix) -- showEvent() is the + # correct Qt idiom for "run once real geometry is available", and + # unlike a single deferred call it also self-corrects on any later + # re-show (e.g. a saved-workspace restore re-applying stale geometry). self.control_panel.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Expanding) - QTimer.singleShot(0, self._fix_control_panel_width) # Core Layout: image (expanding) | control panel (fixed) self.core_layout.addWidget(self.image) @@ -745,11 +750,24 @@ class OMNY_XRayEye(BECWidget, QWidget): sep.setLineWidth(1) return sep + def showEvent(self, event): + """Re-fix the control panel's width every time this widget actually + becomes visible -- see _fix_control_panel_width() for why this can't + just be computed once during __init__/_init_ui().""" + super().showEvent(event) + self._fix_control_panel_width() + def _fix_control_panel_width(self): - """Lock the control panel to its natural width. Scheduled via - QTimer.singleShot(0, ...) from _init_ui() to run on the next event-loop - iteration, after the widget has actually been shown/laid out at least - once -- sizeHint() is not reliable before that point.""" + """Lock the control panel to its natural width, using its current + (now-real) sizeHint() -- see showEvent(), which calls this every time + the widget is actually shown. sizeHint() computed before the widget + has ever been shown/laid out (e.g. synchronously during __init__) is + unreliable: no real screen geometry yet, fonts not fully resolved + (worse over a remote desktop session). A single deferred + QTimer.singleShot(0, ...) call was tried first and was not reliably + late enough in practice; showEvent() also self-corrects on any later + re-show (e.g. a saved-workspace restore re-applying stale geometry), + which a one-shot call cannot.""" self.control_panel.adjustSize() self.control_panel.setFixedWidth(self.control_panel.sizeHint().width())