From 849823e81011230dce220d63d95ec4c7cd62a63e Mon Sep 17 00:00:00 2001 From: un-pogaz <46523284+un-pogaz@users.noreply.github.com> Date: Sun, 18 Jan 2026 13:49:44 +0100 Subject: [PATCH] Bookshelf: fix text color not updated when colors palette is changed --- src/calibre/gui2/library/bookshelf_view.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/library/bookshelf_view.py b/src/calibre/gui2/library/bookshelf_view.py index b1645894f1..1204fc4209 100644 --- a/src/calibre/gui2/library/bookshelf_view.py +++ b/src/calibre/gui2/library/bookshelf_view.py @@ -1323,8 +1323,8 @@ class BookshelfView(MomentumScrollMixin, QAbstractScrollArea): def __init__(self, gui): super().__init__(gui) - self.text_color_for_dark_background = dark_palette().color(QPalette.ColorRole.WindowText) - self.text_color_for_light_background = light_palette().color(QPalette.ColorRole.WindowText) + self.text_color_for_dark_background = QColor() + self.text_color_for_light_background = QColor() self.base_font_size_pts = QFontInfo(self.font()).pointSizeF() self.min_font_size = 0.75 * self.base_font_size_pts @@ -1346,6 +1346,8 @@ class BookshelfView(MomentumScrollMixin, QAbstractScrollArea): self.setMouseTracking(True) self.setFocusPolicy(Qt.FocusPolicy.StrongFocus) + QApplication.instance().palette_changed.connect(self.palette_changed) + self.palette_changed() # Ensure viewport receives mouse events self.viewport().setMouseTracking(True) @@ -1483,6 +1485,10 @@ class BookshelfView(MomentumScrollMixin, QAbstractScrollArea): self.update_ram_cache_size() self.invalidate(clear_spine_width_cache=True) + def palette_changed(self): + self.text_color_for_dark_background = dark_palette().color(QPalette.ColorRole.WindowText) + self.text_color_for_light_background = light_palette().color(QPalette.ColorRole.WindowText) + def view_is_visible(self) -> bool: '''Return if the bookshelf view is visible.''' with suppress(AttributeError): @@ -1847,6 +1853,7 @@ class BookshelfView(MomentumScrollMixin, QAbstractScrollArea): elided_text, _, font = self.get_text_metrics(divider.group_name, '', text_rect.size(), bold=True) painter.save() painter.setFont(font) + painter.setPen(self.palette().color(QPalette.ColorRole.WindowText)) painter.translate(rect.left() + rect.width() // 2, rect.top() + rect.height() // 2) painter.rotate(90 if gprefs['bookshelf_up_to_down'] else -90) sized_rect = painter.drawText(text_rect, Qt.AlignmentFlag.AlignLeft | Qt.AlignmentFlag.AlignVCenter, elided_text)