commit 6a2bd750e9341de7f423edbf7249110705b4d79c
Author: Juergen Spitzmueller <[email protected]>
Date: Sat May 3 09:21:45 2025 +0200
Fix mode setting and run-time switch with Qt >= 6.8 (# 13144)
---
src/frontends/qt/BulletsModule.cpp | 2 +-
src/frontends/qt/ColorCache.cpp | 7 +++----
src/frontends/qt/GuiApplication.cpp | 12 +++++++-----
src/frontends/qt/GuiDelimiter.cpp | 2 +-
src/frontends/qt/GuiView.cpp | 18 +++++++++++++++---
status.24x | 3 +++
6 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/src/frontends/qt/BulletsModule.cpp
b/src/frontends/qt/BulletsModule.cpp
index 95b91c398d..cbceba0a50 100644
--- a/src/frontends/qt/BulletsModule.cpp
+++ b/src/frontends/qt/BulletsModule.cpp
@@ -153,7 +153,7 @@ string const bulletIcon(int f, int c)
QPixmap getSelectedPixmap(QPixmap pixmap, QSize const icon_size)
{
- QPalette palette = QPalette();
+ QPalette palette = guiApp->style()->standardPalette();
QColor text_color = (guiApp->isInDarkMode())
? palette.color(QPalette::Active, QPalette::WindowText)
: Qt::black;
diff --git a/src/frontends/qt/ColorCache.cpp b/src/frontends/qt/ColorCache.cpp
index 2566b75025..de8ff77a56 100644
--- a/src/frontends/qt/ColorCache.cpp
+++ b/src/frontends/qt/ColorCache.cpp
@@ -124,10 +124,9 @@ bool ColorCache::isSystem(ColorCode const color) const
bool ColorCache::isDarkMode() const
{
- QPalette palette = QPalette();
- QColor text_color = palette.color(QPalette::Active,
QPalette::WindowText);
- QColor bg_color = palette.color(QPalette::Active, QPalette::Window);
-
+ 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());
}
diff --git a/src/frontends/qt/GuiApplication.cpp
b/src/frontends/qt/GuiApplication.cpp
index 8e6ae51326..3c62f90ce1 100644
--- a/src/frontends/qt/GuiApplication.cpp
+++ b/src/frontends/qt/GuiApplication.cpp
@@ -640,17 +640,19 @@ IconInfo iconInfo(FuncRequest const & f, bool unknown,
bool rtl)
QPixmap GuiApplication::prepareForDarkMode(QPixmap pixmap) const
{
- QPalette palette = QPalette();
- QColor text_color = palette.color(QPalette::Active,
QPalette::WindowText);
- QColor bg_color = palette.color(QPalette::Active, QPalette::Window);
-
// guess whether we are in dark mode
- if (text_color.black() > bg_color.black())
+ if (!theGuiApp()->isInDarkMode())
// not in dark mode, do nothing
return pixmap;
// create a layer with black text turned to QPalette::WindowText
QPixmap black_overlay(pixmap.size());
+#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
+ QColor text_color =
theGuiApp()->style()->standardPalette().color(QPalette::Active,
QPalette::WindowText);
+#else
+ QPalette palette = QPalette();
+ QColor text_color = palette.color(QPalette::Active,
QPalette::WindowText);
+#endif
black_overlay.fill(text_color);
black_overlay.setMask(pixmap.createMaskFromColor(Qt::black,
Qt::MaskOutColor));
diff --git a/src/frontends/qt/GuiDelimiter.cpp
b/src/frontends/qt/GuiDelimiter.cpp
index 479db87033..5b5b5281e8 100644
--- a/src/frontends/qt/GuiDelimiter.cpp
+++ b/src/frontends/qt/GuiDelimiter.cpp
@@ -92,7 +92,7 @@ struct MathSymbol {
QPixmap getSelectedPixmap(QPixmap pixmap, QSize const icon_size)
{
- QPalette palette = QPalette();
+ QPalette palette = guiApp->style()->standardPalette();
QColor text_color = (guiApp->isInDarkMode())
? palette.color(QPalette::Active, QPalette::WindowText)
: Qt::black;
diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp
index 91f682bbfc..470be5ef67 100644
--- a/src/frontends/qt/GuiView.cpp
+++ b/src/frontends/qt/GuiView.cpp
@@ -658,7 +658,6 @@ GuiView::GuiView(int id)
stat_counts_ = new GuiClickableLabel(statusBar());
stat_counts_->setAlignment(Qt::AlignCenter);
- stat_counts_->setStyleSheet("padding-left: 5px; padding-right: 5px;");
stat_counts_->hide();
statusBar()->addPermanentWidget(stat_counts_);
@@ -1517,7 +1516,9 @@ void GuiView::showStats()
else
stats << toqstr(bformat(_("%1$d Characters (no
Blanks)"), chars));
}
- stat_counts_->setText(stats.join(qt_(", [[stats separator]]")));
+ // we need to add space before and after manually, using stylesheet
+ // would break with dark mode on Qt >= 6.8.
+ stat_counts_->setText(" " + stats.join(qt_(", [[stats separator]]")) +
" ");
stat_counts_->show();
d.time_to_update = d.default_stats_rate;
@@ -1800,7 +1801,17 @@ bool GuiView::event(QEvent * e)
return QMainWindow::event(e);
}
- // dark/light mode runtime switch support, OS-dependent.
+ // dark/light mode runtime switch support
+#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
+ case QEvent::ThemeChange: {
+ guiApp->setPalette(guiApp->style()->standardPalette());
+ // We need to update metrics here to avoid a crash (#12786)
+ theBufferList().changed(true);
+ refillToolbars();
+ return QMainWindow::event(e);
+ }
+#else
+ // Pre 6.8: OS-dependent
// 1. Mac OS X
// Limit to Q_OS_MAC as this unnecessarily would also
// trigger on Linux with grave performance issues
@@ -1819,6 +1830,7 @@ bool GuiView::event(QEvent * e)
refillToolbars();
return QMainWindow::event(e);
}
+#endif
default:
return QMainWindow::event(e);
diff --git a/status.24x b/status.24x
index 0a04996872..14f5bb0d35 100644
--- a/status.24x
+++ b/status.24x
@@ -117,6 +117,9 @@ What's new
- Fix cell splitting in cell equations.
+- Fix (dark/light) mode setting and run-time switch with Qt >= 6.8
+ (bug 13144).
+
- Fix display of some icons in dialogs in dark mode.
- Fix display of menu buttons in dark mode.
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs