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)

This commit is contained in:
Kovid Goyal 2020-05-14 09:49:52 +05:30
parent e0dbdf3c9c
commit 4ecfc43d3d
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -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)