Skip to content

Commit c20f5d5

Browse files
committed
fix(resultviewer): change the way to check darkmode, close #293
1 parent 4a83da0 commit c20f5d5

1 file changed

Lines changed: 17 additions & 3 deletions

File tree

src/resultviewer.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030

3131
#define LEMON_MODULE_NAME "ResultViewer"
3232

33+
static bool shouldApplyDarkFrame() {
34+
const QPalette &defaultPalette = QApplication::palette();
35+
return defaultPalette.color(QPalette::WindowText).lightness() >
36+
defaultPalette.color(QPalette::Window).lightness();
37+
}
38+
3339
ResultViewer::ResultViewer(QWidget *parent) : QTableWidget(parent) {
3440
curContest = nullptr;
3541
deleteContestantAction = new QAction(tr("Delete"), this);
@@ -110,12 +116,20 @@ void ResultViewer::refreshViewer() {
110116
curContest->copySettings(setting);
111117
ColorTheme colors = setting.getCurrentColorTheme();
112118

113-
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
114-
if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark) {
119+
// #if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
120+
// if (QGuiApplication::styleHints()->colorScheme() == Qt::ColorScheme::Dark) {
121+
// colors.invertLightness();
122+
// LOG("Auto dark mode has been set");
123+
// }
124+
// #endif
125+
// https://www.qt.io/blog/dark-mode-on-windows-11-with-qt-6.5
126+
// Waiting QPalette::colorScheme implement
127+
// So we use an alternative method.
128+
if (shouldApplyDarkFrame()) {
115129
colors.invertLightness();
116130
LOG("Auto dark mode has been set");
117131
}
118-
#endif
132+
119133
for (auto &i : taskList) {
120134
headerList << i->getProblemTitle();
121135
}

0 commit comments

Comments
 (0)