From d16df15022b1791b5c052f4f2aab7ee6d18d696b Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 30 Jun 2011 12:40:01 +0100 Subject: [PATCH] Ensure that a column in a book view cannot be sized to bigger than the displayable area. --- src/calibre/gui2/library/views.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index 665112005c..4ba8b0edcf 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -110,6 +110,7 @@ class BooksView(QTableView): # {{{ self.column_header.sectionMoved.connect(self.save_state) self.column_header.setContextMenuPolicy(Qt.CustomContextMenu) self.column_header.customContextMenuRequested.connect(self.show_column_header_context_menu) + self.column_header.sectionResized.connect(self.column_resized) # }}} self._model.database_changed.connect(self.database_changed) @@ -451,7 +452,9 @@ class BooksView(QTableView): # {{{ traceback.print_exc() old_state['sort_history'] = sh + self.column_header.blockSignals(True) self.apply_state(old_state) + self.column_header.blockSignals(False) # Resize all rows to have the correct height if self.model().rowCount(QModelIndex()) > 0: @@ -460,6 +463,15 @@ class BooksView(QTableView): # {{{ self.was_restored = True + def column_resized(self, col, old_size, new_size): + # arbitrary: scroll bar + header + some + max_width = self.width() - (self.verticalScrollBar().width() + + self.verticalHeader().width() + 10) + if new_size > max_width: + self.column_header.blockSignals(True) + self.setColumnWidth(col, max_width) + self.column_header.blockSignals(False) + # }}} # Initialization/Delegate Setup {{{