From e708be5e61fa18de91027ddab18713380e1cefa9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 9 Oct 2022 10:25:23 +0530 Subject: [PATCH] Book list: When displaying yes/no custom columns, render the icon in the center of the column. Fixes #1992261 [Place checkmarks for custom columns in the center](https://bugs.launchpad.net/calibre/+bug/1992261) --- src/calibre/gui2/library/delegates.py | 9 +++++++++ src/calibre/gui2/library/models.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index 3140d69fd6..2823241cc4 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -747,6 +747,15 @@ class CcBoolDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{ else 1 if not val else 0 editor.setCurrentIndex(val) + def paint(self, painter, option, index): + text, icon = index.data(Qt.ItemDataRole.DisplayRole), index.data(Qt.ItemDataRole.DecorationRole) + if (not text and not icon) or text or not icon: + return super().paint(painter, option, index) + dummy = index.model().index(-1, -1) + super().paint(painter, option, dummy) + style = QApplication.style() + style.drawItemPixmap(painter, option.rect, Qt.AlignmentFlag.AlignCenter, icon) + # }}} diff --git a/src/calibre/gui2/library/models.py b/src/calibre/gui2/library/models.py index 8b189fcdff..0aa644d384 100644 --- a/src/calibre/gui2/library/models.py +++ b/src/calibre/gui2/library/models.py @@ -927,7 +927,7 @@ class BooksModel(QAbstractTableModel): # {{{ return (None if v is None else (_('Yes') if v else _('No'))) else: def func(idx): - return(None) + return None else: def func(idx): return None