From 6c63a1fa3e979fc607e213b62a1eb4e9caeb0828 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 21 Jan 2026 09:36:04 +0530 Subject: [PATCH] Only show the Sort button on the search bar if the Sort By action has not been added to the search bar by the user. Fixes #2138770 [[Enhancement] Sort By - List view](https://bugs.launchpad.net/calibre/+bug/2138770) --- src/calibre/gui2/bars.py | 4 ++++ src/calibre/gui2/init.py | 2 +- src/calibre/gui2/layout.py | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/bars.py b/src/calibre/gui2/bars.py index 73300a3d3f..829f019955 100644 --- a/src/calibre/gui2/bars.py +++ b/src/calibre/gui2/bars.py @@ -650,6 +650,7 @@ class SearchToolBar(QHBoxLayout): QHBoxLayout.__init__(self) self.search_tool_bar_widgets = [] self.gui = gui + self.has_sort_by_button = False self.donate_button = None def init_bar(self, actions): @@ -661,6 +662,7 @@ class SearchToolBar(QHBoxLayout): self.search_tool_bar_widgets = [] self.search_tool_bar_actions = [] + self.has_sort_by_button = False for what in gprefs['action-layout-searchbar']: if what is None: frame = QFrame() @@ -672,6 +674,8 @@ class SearchToolBar(QHBoxLayout): self.search_tool_bar_widgets.append(frame) self.search_tool_bar_actions.append(None) elif what in self.gui.iactions: + if what == 'Sort By': + self.has_sort_by_button = True act = self.gui.iactions[what] qact = act.qaction tb = RightClickButton() diff --git a/src/calibre/gui2/init.py b/src/calibre/gui2/init.py index cb550812d3..56c7f15895 100644 --- a/src/calibre/gui2/init.py +++ b/src/calibre/gui2/init.py @@ -298,7 +298,7 @@ class AlternateViewsButtons(LayoutButton): # {{{ if btn.isChecked(): btn.update_state(False) self.gui.library_view.alternate_views.show_view(self.view_name if show else None) - self.gui.sort_button.setVisible(show) + self.gui.show_sort_button_for_alternate_view(show) self.gui.group_by_button.setVisible(self.needs_group_by and show) AlternateViewsButtons.ignore_toggles = False # }}} diff --git a/src/calibre/gui2/layout.py b/src/calibre/gui2/layout.py index 374e316d83..09da7932b3 100644 --- a/src/calibre/gui2/layout.py +++ b/src/calibre/gui2/layout.py @@ -399,4 +399,9 @@ class MainWindowMixin: # {{{ smw.setText(_('

Shutting down

') + message) # Force processing the events needed to show the message QCoreApplication.processEvents() + + def show_sort_button_for_alternate_view(self, show: bool = True) -> None: + if self.bars_manager.search_tool_bar.has_sort_by_button: + show = False + self.sort_button.setVisible(show) # }}}