Add StyleSheet automatic reload function

This commit is contained in:
chenhuijun
2024-04-17 09:39:36 +08:00
parent 4c9a7e83d7
commit c6de941d95
2 changed files with 20 additions and 0 deletions

View File

@@ -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
$<$<CONFIG:Debug>:_DEBUG>
)
if(NOT UNIX)
find_program(POWERSHELL_PATH NAMES powershell)

View File

@@ -19,6 +19,7 @@
#include "utilities/TouchScreenSignalSender.h"
#include "keyboard/KeyboardManager.h"
#include "appvals/AppGlobalValues.h"
#include <QFileSystemWatcher>
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*>(QApplication::instance())->setStyleSheet(file.readAll());
file.close();
qDebug()<<"style updated!";
}
});
#endif
AppGlobalValues::setDBconnected(false);
MainWindow w;
DialogManager::Default()->init(&w);