From 10b02ca2f14888c5c7d13abdfb7673dc89c10973 Mon Sep 17 00:00:00 2001 From: x01dc Date: Thu, 17 Sep 2026 15:37:25 +0200 Subject: [PATCH] fix(xrayeye): defer control-panel width-fixing until after first show _init_ui() locked the control panel to a fixed width computed from sizeHint() called synchronously during construction -- before the widget had ever been shown/laid out, with no real screen geometry and fonts not fully resolved yet (worse over a remote desktop session). Reported live: the widget opens correctly sized for a moment, then the image area visibly collapses down to a sliver as the (wrong) fixed width gets applied, recoverable only by manually resizing the window (which doesn't fix the wrong width itself, just gives the image enough leftover space to look normal again despite it). Defer the actual sizeHint()/setFixedWidth() call via QTimer.singleShot(0, ...) so it runs on the next event-loop iteration, after the widget has actually been shown/laid out at least once -- same effect a manual resize was achieving, but automatic and correct the first time. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_01Lx3KffiFyyDMKT8vvPENUW --- .../bec_widgets/widgets/xray_eye/x_ray_eye.py | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 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 e170f304..6ed7758d 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 @@ -580,11 +580,15 @@ class OMNY_XRayEye(BECWidget, QWidget): self._update_calibration_readout() self.control_panel_layout.addLayout(form) - # Fix panel width and allow vertical expansion - self.control_panel.adjustSize() - p_hint = self.control_panel.sizeHint() - self.control_panel.setFixedWidth(p_hint.width()) + # Fix panel width and allow vertical expansion. The actual width-fixing + # is deferred (see _fix_control_panel_width()) rather than computed + # 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). 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) @@ -741,6 +745,14 @@ class OMNY_XRayEye(BECWidget, QWidget): sep.setLineWidth(1) return sep + 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.""" + self.control_panel.adjustSize() + self.control_panel.setFixedWidth(self.control_panel.sizeHint().width()) + def _init_gui_trigger(self): self.dev.omny_xray_gui.read() self.dev.fsh.read()