DolphinQt: reset stylesheets on colorSchemeChanged

This is required for switching system color scheme
(dark/light) dynamically at runtime.
This commit is contained in:
Shawn Hoffman 2023-04-25 00:12:59 -07:00
parent 8c2e924255
commit bb227ad7bb
4 changed files with 42 additions and 6 deletions

View File

@ -7,10 +7,12 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <QGuiApplication>
#include <QHBoxLayout> #include <QHBoxLayout>
#include <QLabel> #include <QLabel>
#include <QMenu> #include <QMenu>
#include <QPushButton> #include <QPushButton>
#include <QStyleHints>
#include <QTableWidget> #include <QTableWidget>
#include <QVBoxLayout> #include <QVBoxLayout>
@ -30,6 +32,10 @@
#include "DolphinQt/QtUtils/ModalMessageBox.h" #include "DolphinQt/QtUtils/ModalMessageBox.h"
#include "DolphinQt/Settings.h" #include "DolphinQt/Settings.h"
static const QString RECORD_BUTTON_STYLESHEET =
QStringLiteral("QPushButton:checked { background-color: rgb(150, 0, 0); border-style: solid; "
"border-width: 3px; border-color: rgb(150,0,0); color: rgb(255, 255, 255);}");
CodeDiffDialog::CodeDiffDialog(CodeWidget* parent) : QDialog(parent), m_code_widget(parent) CodeDiffDialog::CodeDiffDialog(CodeWidget* parent) : QDialog(parent), m_code_widget(parent)
{ {
setWindowTitle(tr("Code Diff Tool")); setWindowTitle(tr("Code Diff Tool"));
@ -54,9 +60,7 @@ void CodeDiffDialog::CreateWidgets()
m_include_btn = new QPushButton(tr("Code has been executed")); m_include_btn = new QPushButton(tr("Code has been executed"));
m_record_btn = new QPushButton(tr("Start Recording")); m_record_btn = new QPushButton(tr("Start Recording"));
m_record_btn->setCheckable(true); m_record_btn->setCheckable(true);
m_record_btn->setStyleSheet( m_record_btn->setStyleSheet(RECORD_BUTTON_STYLESHEET);
QStringLiteral("QPushButton:checked { background-color: rgb(150, 0, 0); border-style: solid; "
"border-width: 3px; border-color: rgb(150,0,0); color: rgb(255, 255, 255);}"));
m_exclude_btn->setEnabled(false); m_exclude_btn->setEnabled(false);
m_include_btn->setEnabled(false); m_include_btn->setEnabled(false);
@ -105,6 +109,13 @@ void CodeDiffDialog::CreateWidgets()
void CodeDiffDialog::ConnectWidgets() void CodeDiffDialog::ConnectWidgets()
{ {
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this,
[this](Qt::ColorScheme colorScheme) {
m_record_btn->setStyleSheet(RECORD_BUTTON_STYLESHEET);
});
#endif
connect(m_record_btn, &QPushButton::toggled, this, &CodeDiffDialog::OnRecord); connect(m_record_btn, &QPushButton::toggled, this, &CodeDiffDialog::OnRecord);
connect(m_include_btn, &QPushButton::pressed, [this]() { Update(true); }); connect(m_include_btn, &QPushButton::pressed, [this]() { Update(true); });
connect(m_exclude_btn, &QPushButton::pressed, [this]() { Update(false); }); connect(m_exclude_btn, &QPushButton::pressed, [this]() { Update(false); });

View File

@ -19,6 +19,7 @@
#include <QPainter> #include <QPainter>
#include <QResizeEvent> #include <QResizeEvent>
#include <QScrollBar> #include <QScrollBar>
#include <QStyleHints>
#include <QStyledItemDelegate> #include <QStyledItemDelegate>
#include <QTableWidgetItem> #include <QTableWidgetItem>
#include <QWheelEvent> #include <QWheelEvent>
@ -161,6 +162,11 @@ CodeViewWidget::CodeViewWidget() : m_system(Core::System::GetInstance())
FontBasedSizing(); FontBasedSizing();
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this,
[this](Qt::ColorScheme colorScheme) { OnSelectionChanged(); });
#endif
connect(this, &CodeViewWidget::customContextMenuRequested, this, &CodeViewWidget::OnContextMenu); connect(this, &CodeViewWidget::customContextMenuRequested, this, &CodeViewWidget::OnContextMenu);
connect(this, &CodeViewWidget::itemSelectionChanged, this, &CodeViewWidget::OnSelectionChanged); connect(this, &CodeViewWidget::itemSelectionChanged, this, &CodeViewWidget::OnSelectionChanged);
connect(&Settings::Instance(), &Settings::DebugFontChanged, this, &QWidget::setFont); connect(&Settings::Instance(), &Settings::DebugFontChanged, this, &QWidget::setFont);

View File

@ -9,11 +9,13 @@
#include <QGridLayout> #include <QGridLayout>
#include <QGroupBox> #include <QGroupBox>
#include <QGuiApplication>
#include <QLabel> #include <QLabel>
#include <QLineEdit> #include <QLineEdit>
#include <QListWidget> #include <QListWidget>
#include <QPushButton> #include <QPushButton>
#include <QSplitter> #include <QSplitter>
#include <QStyleHints>
#include <QTableWidget> #include <QTableWidget>
#include <QWidget> #include <QWidget>
@ -28,6 +30,10 @@
#include "DolphinQt/Host.h" #include "DolphinQt/Host.h"
#include "DolphinQt/Settings.h" #include "DolphinQt/Settings.h"
static const QString BOX_SPLITTER_STYLESHEET = QStringLiteral(
"QSplitter::handle { border-top: 1px dashed black; width: 1px; margin-left: 10px; "
"margin-right: 10px; }");
CodeWidget::CodeWidget(QWidget* parent) : QDockWidget(parent), m_system(Core::System::GetInstance()) CodeWidget::CodeWidget(QWidget* parent) : QDockWidget(parent), m_system(Core::System::GetInstance())
{ {
setWindowTitle(tr("Code")); setWindowTitle(tr("Code"));
@ -104,9 +110,7 @@ void CodeWidget::CreateWidgets()
m_search_address->setPlaceholderText(tr("Search Address")); m_search_address->setPlaceholderText(tr("Search Address"));
m_box_splitter = new QSplitter(Qt::Vertical); m_box_splitter = new QSplitter(Qt::Vertical);
m_box_splitter->setStyleSheet(QStringLiteral( m_box_splitter->setStyleSheet(BOX_SPLITTER_STYLESHEET);
"QSplitter::handle { border-top: 1px dashed black; width: 1px; margin-left: 10px; "
"margin-right: 10px; }"));
auto add_search_line_edit = [this](const QString& name, QListWidget* list_widget) { auto add_search_line_edit = [this](const QString& name, QListWidget* list_widget) {
auto* widget = new QWidget; auto* widget = new QWidget;
@ -154,6 +158,13 @@ void CodeWidget::CreateWidgets()
void CodeWidget::ConnectWidgets() void CodeWidget::ConnectWidgets()
{ {
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this,
[this](Qt::ColorScheme colorScheme) {
m_box_splitter->setStyleSheet(BOX_SPLITTER_STYLESHEET);
});
#endif
connect(m_search_address, &QLineEdit::textChanged, this, &CodeWidget::OnSearchAddress); connect(m_search_address, &QLineEdit::textChanged, this, &CodeWidget::OnSearchAddress);
connect(m_search_address, &QLineEdit::returnPressed, this, &CodeWidget::OnSearchAddress); connect(m_search_address, &QLineEdit::returnPressed, this, &CodeWidget::OnSearchAddress);
connect(m_search_symbols, &QLineEdit::textChanged, this, &CodeWidget::OnSearchSymbols); connect(m_search_symbols, &QLineEdit::textChanged, this, &CodeWidget::OnSearchSymbols);

View File

@ -14,6 +14,7 @@
#include <QIcon> #include <QIcon>
#include <QMimeData> #include <QMimeData>
#include <QStackedWidget> #include <QStackedWidget>
#include <QStyleHints>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QWindow> #include <QWindow>
@ -238,6 +239,13 @@ MainWindow::MainWindow(std::unique_ptr<BootParameters> boot_parameters,
ConnectMenuBar(); ConnectMenuBar();
ConnectHotkeys(); ConnectHotkeys();
#if QT_VERSION >= QT_VERSION_CHECK(6, 5, 0)
connect(QGuiApplication::styleHints(), &QStyleHints::colorSchemeChanged, this,
[](Qt::ColorScheme colorScheme) {
Settings::Instance().SetCurrentUserStyle(Settings::Instance().GetCurrentUserStyle());
});
#endif
connect(m_cheats_manager, &CheatsManager::OpenGeneralSettings, this, connect(m_cheats_manager, &CheatsManager::OpenGeneralSettings, this,
&MainWindow::ShowGeneralWindow); &MainWindow::ShowGeneralWindow);