From c6de941d954b9c0702f911a412a333bc57ad0014 Mon Sep 17 00:00:00 2001 From: chenhuijun Date: Wed, 17 Apr 2024 09:39:36 +0800 Subject: [PATCH] Add StyleSheet automatic reload function --- CMakeLists.txt | 6 ++++++ src/main.cpp | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5e388c0..c7634e8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,12 @@ if(${Req_FOUND}) target_link_libraries(${PROJECT_NAME} Req) endif() +target_compile_definitions(${PROJECT_NAME} + PRIVATE + # If the debug configuration pass the DEBUG define to the compiler + $<$:_DEBUG> +) + if(NOT UNIX) find_program(POWERSHELL_PATH NAMES powershell) diff --git a/src/main.cpp b/src/main.cpp index f74317e..7c1ccda 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,6 +19,7 @@ #include "utilities/TouchScreenSignalSender.h" #include "keyboard/KeyboardManager.h" #include "appvals/AppGlobalValues.h" +#include QString loadFontFromFile(QString path) { @@ -75,6 +76,19 @@ int main(int argc, char* argv[]) { a.setStyleSheet(QLatin1String(file.readAll())); } + #ifdef _DEBUG + QFileSystemWatcher fileWatcher; + fileWatcher.addPath("../src/stylesheet/Dark2.css"); + QObject::connect(&fileWatcher, &QFileSystemWatcher::fileChanged, [](const QString &path){ + QFile file(path); + if (file.open(QIODevice::ReadOnly)) + { + qobject_cast(QApplication::instance())->setStyleSheet(file.readAll()); + file.close(); + qDebug()<<"style updated!"; + } + }); + #endif AppGlobalValues::setDBconnected(false); MainWindow w; DialogManager::Default()->init(&w);