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())