From 4ecfc43d3df57779ce78ec36649a36d50a92bfa2 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 14 May 2020 09:49:52 +0530 Subject: [PATCH] Book list column header context menu: Add an entry to resize the column to fit its current contents. Fixes #1878450 [[Enhancement] Maximize a column width to fit all text](https://bugs.launchpad.net/calibre/+bug/1878450) --- src/calibre/gui2/library/views.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index e7f05d8506..8d77c646ee 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -471,6 +471,8 @@ class BooksView(QTableView): # {{{ ans.addSeparator() ans.addAction(_('Shrink column if it is too wide to fit'), partial(self.resize_column_to_fit, view, col)) + ans.addAction(_('Resize column to fit contents'), + partial(self.fit_column_to_contents, view, col)) ans.addAction(_('Restore default layout'), partial(handler, action='defaults')) if self.can_add_columns: ans.addAction( @@ -829,6 +831,10 @@ class BooksView(QTableView): # {{{ w = view.columnWidth(col) restrict_column_width(view, col, w, w) + def fit_column_to_contents(self, view, column): + col = self.column_map.index(column) + view.resizeColumnToContents(col) + def column_resized(self, col, old_size, new_size): restrict_column_width(self, col, old_size, new_size)