mirror of
https://github.com/86Box/86Box.git
synced 2026-02-25 04:45:31 -07:00
Manager: Fix style not reacting to Windows light/dark mode change
Add a native event filter for dark mode update, move the function that queries the current theme to qt_util.cpp and make widgets with custom stylesheets update their style on update
This commit is contained in:
@@ -19,6 +19,15 @@
|
||||
#include "ui_qt_vmmanager_detailsection.h"
|
||||
|
||||
#include <QPushButton>
|
||||
#include "qt_util.hpp"
|
||||
|
||||
#define HEADER_STYLESHEET_LIGHT "background-color: palette(midlight);"
|
||||
#ifdef Q_OS_WINDOWS
|
||||
# define HEADER_STYLESHEET_DARK "background-color: #616161;"
|
||||
# define BACKGROUND_STYLESHEET_DARK "background-color: #272727;"
|
||||
#else
|
||||
# define HEADER_STYLESHEET_DARK "background-color: palette(mid);"
|
||||
#endif
|
||||
|
||||
const QString VMManagerDetailSection::sectionSeparator = ";";
|
||||
using namespace VMManager;
|
||||
@@ -40,21 +49,18 @@ VMManagerDetailSection(const QString §ionName)
|
||||
|
||||
// Simple method to try and determine if light mode is enabled on the host
|
||||
#ifdef Q_OS_WINDOWS
|
||||
extern bool windows_is_light_theme();
|
||||
const bool lightMode = windows_is_light_theme();
|
||||
const bool lightMode = util::isWindowsLightTheme();
|
||||
#else
|
||||
const bool lightMode = QApplication::palette().window().color().value() > QApplication::palette().windowText().color().value();
|
||||
#endif
|
||||
// Alternate layout
|
||||
if ( lightMode) {
|
||||
ui->collapseButtonHolder->setStyleSheet("background-color: palette(midlight);");
|
||||
if (lightMode) {
|
||||
ui->collapseButtonHolder->setStyleSheet(HEADER_STYLESHEET_LIGHT);
|
||||
} else {
|
||||
#ifdef Q_OS_WINDOWS
|
||||
ui->outerFrame->setStyleSheet("background-color: #272727;");
|
||||
ui->collapseButtonHolder->setStyleSheet("background-color: #616161;");
|
||||
#else
|
||||
ui->collapseButtonHolder->setStyleSheet("background-color: palette(mid);");
|
||||
ui->outerFrame->setStyleSheet(BACKGROUND_STYLESHEET_DARK);
|
||||
#endif
|
||||
ui->collapseButtonHolder->setStyleSheet(HEADER_STYLESHEET_DARK);
|
||||
}
|
||||
const auto sectionLabel = new QLabel(sectionName);
|
||||
sectionLabel->setStyleSheet(sectionLabel->styleSheet().append("font-weight: bold;"));
|
||||
@@ -214,6 +220,21 @@ VMManagerDetailSection::clear()
|
||||
ui->detailFrame->setLayout(frameGridLayout);
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WINDOWS
|
||||
void
|
||||
VMManagerDetailSection::updateStyle()
|
||||
{
|
||||
const bool lightMode = util::isWindowsLightTheme();
|
||||
if (lightMode) {
|
||||
ui->outerFrame->setStyleSheet("");
|
||||
ui->collapseButtonHolder->setStyleSheet(HEADER_STYLESHEET_LIGHT);
|
||||
} else {
|
||||
ui->outerFrame->setStyleSheet(BACKGROUND_STYLESHEET_DARK);
|
||||
ui->collapseButtonHolder->setStyleSheet(HEADER_STYLESHEET_DARK);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// QT for Linux and Windows doesn't have the same default margins as QT on MacOS.
|
||||
// For consistency in appearance we'll have to return the margins on a per-OS basis
|
||||
QMargins
|
||||
|
||||
Reference in New Issue
Block a user