From dfef67faeaf0d41372b12565766cb27902f9cc64 Mon Sep 17 00:00:00 2001 From: Marcin Zawalski Date: Tue, 4 Aug 2026 08:46:18 +0200 Subject: [PATCH] fix: keep the session panel stacked when its sections are collapsed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A collapsed section is pinned to its header height with stretch 0, so with every section shut nothing in the panel could take the leftover height and Qt spread it into the gaps between the toolbar, the filter row and the headers — the panel's contents ended up evenly spaced down the whole dock. A trailing stretch absorbs it. Stretch 0 keeps an open section's share intact. Hit most easily before a library exists: that section is hidden until it has roots, leaving the film strip as the only one to collapse. Fixes #754 --- negpy/desktop/view/sidebar/files.py | 3 +++ tests/test_session_panel.py | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/negpy/desktop/view/sidebar/files.py b/negpy/desktop/view/sidebar/files.py index d056b5a7..9abd26c2 100644 --- a/negpy/desktop/view/sidebar/files.py +++ b/negpy/desktop/view/sidebar/files.py @@ -549,6 +549,9 @@ def _init_ui(self) -> None: layout.addWidget(self.library_section) layout.addWidget(self.frames_section) + # Absorbs the surplus when every section is collapsed — otherwise Qt spreads it + # into the gaps between the rows above. Stretch 0 leaves an open section its share. + layout.addStretch(0) self._rebalance_sections() # Applied after list_view exists — the filter prunes selection against the view. diff --git a/tests/test_session_panel.py b/tests/test_session_panel.py index b067c590..c9187087 100644 --- a/tests/test_session_panel.py +++ b/tests/test_session_panel.py @@ -71,6 +71,19 @@ def test_a_collapsed_section_keeps_only_its_header(panel): assert browser.layout().stretch(browser.layout().indexOf(browser.frames_section)) > 0 +def test_collapsing_both_sections_keeps_the_panel_top_aligned(panel, qapp): + """With nothing expanded the leftover height must not spread into the gaps (#754).""" + browser = panel.file_browser + browser.library_section.toggle_button.setChecked(False) + browser.frames_section.toggle_button.setChecked(False) + + browser.resize(300, 900) + browser.show() + qapp.processEvents() + + assert browser.frames_section.y() < 200 # ~115 stacked, ~707 spread + + def test_expanding_a_section_gives_it_back_a_share(panel): browser = panel.file_browser browser.frames_section.toggle_button.setChecked(False)