From d6bac20c58ef41e654f318c73453d6c4c8e06ba1 Mon Sep 17 00:00:00 2001 From: RumovZ Date: Mon, 29 Mar 2021 11:40:18 +0200 Subject: [PATCH] Fix issues with scrolling row into view 1) Check whether full row height is in viewport instead of just the top left corner. 2) Add timer before scrolling to current row so editor will already be set up. --- qt/aqt/table.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/qt/aqt/table.py b/qt/aqt/table.py index 1f4bbe6c9..af80022fb 100644 --- a/qt/aqt/table.py +++ b/qt/aqt/table.py @@ -417,7 +417,8 @@ class Table: current = current or rows[0] self._select_rows(rows) self._set_current(current) - self._scroll_to_row(current) + # editor may pop up and hide the row later on + QTimer.singleShot(100, lambda: self._scroll_to_row(current)) if self.len_selection() == 0: # no row change will fire self.browser.onRowChanged(QItemSelection(), QItemSelection()) @@ -462,8 +463,9 @@ class Table: def _scroll_to_row(self, row: int) -> None: """Scroll vertically to row.""" - position = self._view.rowViewportPosition(row) - visible = 0 <= position < self._view.viewport().height() + top_border = self._view.rowViewportPosition(row) + bottom_border = top_border + self._view.rowHeight(0) + visible = top_border >= 0 and bottom_border < self._view.viewport().height() if not visible: horizontal = self._view.horizontalScrollBar().value() self._view.scrollTo(self._model.index(row, 0), self._view.PositionAtCenter)