grid: force vertical scrollbar AlwaysOn to fix column-collapse race
The ThumbnailGrid was setting horizontal scrollbar to AlwaysOff explicitly but leaving the vertical scrollbar at the default AsNeeded. When content first overflowed enough to summon the vertical scrollbar, the viewport width dropped by ~14-16px (scrollbar width), and FlowLayout's column count flipped down by 1 because the integer-division formula sat right at a boundary. columns = max(1, w // (THUMB_SIZE + THUMB_SPACING)) For THUMB_SIZE=180 + THUMB_SPACING=6 (per-column step = 186): - viewport 1122 → 6 columns - viewport 1108 (1122 - 14 scrollbar) → 5 columns If the popout/main window happened to sit anywhere in the range where `viewport_width % 186 < scrollbar_width`, the column count flipped when the scrollbar appeared. The user saw "the grid collapses by a column when switching to a post" — the actual trigger isn't post selection, it's the grid scrolling enough to bring the selected thumbnail into view, which makes content visibly overflow and summons the scrollbar. From the user's perspective the two events looked correlated. Fix: setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn). The scrollbar is now always visible, its width is always reserved in the viewport, and FlowLayout's column count is stable across the scrollbar visibility transition. Trade-off: a slim grey scrollbar strip is always visible on the right edge of the grid, even when content fits on one screen and would otherwise have no scrollbar. For an image grid that almost always overflows in practice, this is the standard behavior (most file browsers / image viewers do the same) and the cost is invisible after the first few thumbnails load. Affects all three tabs (Browse / Bookmarks / Library) since they all use ThumbnailGrid from grid.py. Verification: - Phase A test suite (16 tests) still passes - Popout state machine tests (65 tests) still pass - Total: 81 / 81 automated tests green - Imports clean - Manual: open the popout to a column boundary (resize window width such that the grid is exactly N columns wide before any scrolling), then scroll down — column count should NOT flip to N-1 anymore.
This commit is contained in:
parent
0ef3643b32
commit
69f75fc98f
@ -364,6 +364,18 @@ class ThumbnailGrid(QScrollArea):
|
|||||||
self.setWidget(self._flow)
|
self.setWidget(self._flow)
|
||||||
self.setWidgetResizable(True)
|
self.setWidgetResizable(True)
|
||||||
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
self.setHorizontalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
|
||||||
|
# Force the vertical scrollbar to always be visible so its width
|
||||||
|
# is always reserved in the viewport. With the default
|
||||||
|
# ScrollBarAsNeeded, the viewport width drops by ~14-16px when
|
||||||
|
# the scrollbar first appears, and FlowLayout's column count
|
||||||
|
# (computed as `viewport.width() // (THUMB_SIZE + THUMB_SPACING)`)
|
||||||
|
# flips down by 1 if the grid width was sitting within a
|
||||||
|
# scrollbar-width of a column boundary. Visible symptom: the
|
||||||
|
# grid collapses by a column the first time content overflows.
|
||||||
|
# AlwaysOn keeps the scrollbar's width reserved permanently so
|
||||||
|
# the column math is stable across the scrollbar visibility
|
||||||
|
# transition.
|
||||||
|
self.setVerticalScrollBarPolicy(Qt.ScrollBarPolicy.ScrollBarAlwaysOn)
|
||||||
self._thumbs: list[ThumbnailWidget] = []
|
self._thumbs: list[ThumbnailWidget] = []
|
||||||
self._selected_index = -1
|
self._selected_index = -1
|
||||||
self._multi_selected: set[int] = set()
|
self._multi_selected: set[int] = set()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user