commit 71e20a675b238b0eafdc2055a20d6220f8f18d87
Author: Juergen Spitzmueller <[email protected]>
Date:   Sun Dec 28 10:03:18 2025 +0100

    Check whether dark/light mode switch happened before reloading toolbars
    
    Also factor out dark palette test
    
    (cherry picked from commit 9b57990e4339a9735778e3ac873e9334821765d1)
---
 src/frontends/qt/ColorCache.cpp | 6 ++----
 src/frontends/qt/GuiView.cpp    | 9 +++++++--
 src/frontends/qt/qt_helpers.cpp | 9 +++++++++
 src/frontends/qt/qt_helpers.h   | 4 ++++
 status.24x                      | 3 +++
 5 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/src/frontends/qt/ColorCache.cpp b/src/frontends/qt/ColorCache.cpp
index de8ff77a56..b922847e2d 100644
--- a/src/frontends/qt/ColorCache.cpp
+++ b/src/frontends/qt/ColorCache.cpp
@@ -13,6 +13,7 @@
 #include "ColorCache.h"
 
 #include "LyXRC.h"
+#include "qt_helpers.h"
 
 #include "Color.h"
 #include "ColorSet.h"
@@ -124,10 +125,7 @@ bool ColorCache::isSystem(ColorCode const color) const
 
 bool ColorCache::isDarkMode() const
 {
-       QColor text_color = pal_.color(QPalette::Active, QPalette::WindowText);
-       QColor bg_color = pal_.color(QPalette::Active, QPalette::Window);
-
-       return (text_color.black() < bg_color.black());
+       return frontend::isPaletteDark(pal_);
 }
 
 
diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp
index 15019c5526..712f1fa8c2 100644
--- a/src/frontends/qt/GuiView.cpp
+++ b/src/frontends/qt/GuiView.cpp
@@ -1797,10 +1797,15 @@ bool GuiView::event(QEvent * e)
        // dark/light mode runtime switch support
 #if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
        case QEvent::ThemeChange: {
-               guiApp->setPalette(guiApp->style()->standardPalette());
+               QPalette currentPalette = guiApp->palette();
+               QPalette newPalette = guiApp->style()->standardPalette();
+               guiApp->setPalette(newPalette);
                // We need to update metrics here to avoid a crash (#12786)
                theBufferList().changed(true);
-               refillToolbars();
+               if (isPaletteDark(currentPalette) != isPaletteDark(newPalette))
+                       // we need to refill the toolbar only if we really
+                       // switched from dark to light or vice versa
+                       refillToolbars();
                return QMainWindow::event(e);
        }
 #else
diff --git a/src/frontends/qt/qt_helpers.cpp b/src/frontends/qt/qt_helpers.cpp
index d49cca4645..4766ae43f7 100644
--- a/src/frontends/qt/qt_helpers.cpp
+++ b/src/frontends/qt/qt_helpers.cpp
@@ -395,6 +395,15 @@ void showTarget(string const & target_in, Buffer const & 
buf)
                        bformat(_("The target `%1$s' could not be resolved."),
                                from_utf8(target)));
 }
+
+bool isPaletteDark(QPalette const & pal)
+{
+       QColor text_color = pal.color(QPalette::Active, QPalette::WindowText);
+       QColor bg_color = pal.color(QPalette::Active, QPalette::Window);
+
+       return (text_color.black() < bg_color.black());
+}
+
 } // namespace frontend
 
 QString const qt_(char const * str, const char *)
diff --git a/src/frontends/qt/qt_helpers.h b/src/frontends/qt/qt_helpers.h
index 59b5e188b1..2ac6e35cff 100644
--- a/src/frontends/qt/qt_helpers.h
+++ b/src/frontends/qt/qt_helpers.h
@@ -26,6 +26,7 @@
 
 class QComboBox;
 class QLineEdit;
+class QPalette;
 class QString;
 class QWidget;
 
@@ -98,6 +99,9 @@ void showDirectory(support::FileName const & directory);
 void showTarget(std::string const & target,
                Buffer const & buf);
 
+/// Check if a palette represents dark mode
+bool isPaletteDark(QPalette const & pal);
+
 } // namespace frontend
 
 
diff --git a/status.24x b/status.24x
index 9fdba1ef6c..7644e4eeaa 100644
--- a/status.24x
+++ b/status.24x
@@ -89,6 +89,9 @@ What's new
 
 - Fix pasting of multiple-cell plaintext to tables with cells selected.
 
+- Fix unnecessary reloading of toolbar icons on theme change without
+  (dark/light) mode change with Qt6.
+
 
 * INTERNALS
 
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to