From bcfbe8e00325252f284543c8eb0aac2fb7959cdc Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Sat, 19 Mar 2022 16:50:15 +0000 Subject: [PATCH] Fix regression documented in " Columns won't keep size in 5.39" (https://www.mobileread.com/forums/showthread.php?t=345781) --- src/calibre/gui2/library/views.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index d39b10bc1c..91c6eaa1b3 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -304,6 +304,7 @@ class BooksView(QTableView): # {{{ # {{{ Column Header setup self.can_add_columns = True self.was_restored = False + self.allow_save_state = True self.column_header = HeaderView(Qt.Orientation.Horizontal, self) self.pin_view.column_header = HeaderView(Qt.Orientation.Horizontal, self.pin_view) self.setHorizontalHeader(self.column_header) @@ -692,7 +693,7 @@ class BooksView(QTableView): # {{{ def save_state(self): # Only save if we have been initialized (set_database called) - if len(self.column_map) > 0 and self.was_restored: + if len(self.column_map) > 0 and self.was_restored and self.allow_save_state: state = self.get_state() self.write_state(state) if self.is_library_view: @@ -742,7 +743,10 @@ class BooksView(QTableView): # {{{ if col in cmap: pmap[pos] = col need_save_state = False - self.column_header.blockSignals(True) + # Resetting column positions triggers a save state. There can be a lot + # of these. Batch them up and do it at the end. + # Can't use blockSignals() because that prevents needed processing somewhere + self.allow_save_state = False for pos in sorted(pmap.keys()): col = pmap[pos] idx = cmap[col] @@ -750,7 +754,7 @@ class BooksView(QTableView): # {{{ if current_pos != pos: need_save_state = True h.moveSection(current_pos, pos) - self.column_header.blockSignals(False) + self.allow_save_state = True if need_save_state and save_state: self.save_state() # Because of a bug in Qt 5 we have to ensure that the header is actually