diff --git a/dist/scripts/windeployqt.ps1 b/dist/scripts/windeployqt.ps1 index e8865b56..8bf37bcb 100755 --- a/dist/scripts/windeployqt.ps1 +++ b/dist/scripts/windeployqt.ps1 @@ -42,6 +42,12 @@ if ($env:buildArch -eq 'Arm64') { windeployqt --no-compiler-runtime $argForceOpenSsl bin/qView.exe } +if ($qtVersion -ge [version]'6.8.1') { + # Copy font so windows11 style can work on Windows 10 + New-Item -ItemType Directory -Path "bin\fonts" -Force + Copy-Item -Path "dist\win\fonts\Segoe Fluent Icons.ttf" -Destination "bin\fonts" +} + if ($NightlyVersion -eq '') { # Call innomake if we are not building a nightly version (no version passed) & "dist/scripts/innomake.ps1" diff --git a/dist/win/fonts/Segoe Fluent Icons.ttf b/dist/win/fonts/Segoe Fluent Icons.ttf new file mode 100644 index 00000000..8f05a4bb Binary files /dev/null and b/dist/win/fonts/Segoe Fluent Icons.ttf differ diff --git a/src/main.cpp b/src/main.cpp index 62374de1..64c7fe9d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,7 @@ #include "qvwin32functions.h" #include +#include int main(int argc, char *argv[]) { @@ -10,8 +11,33 @@ int main(int argc, char *argv[]) QCoreApplication::setOrganizationName("qView"); QCoreApplication::setApplicationName("qView"); QCoreApplication::setApplicationVersion(QString::number(VERSION)); + + QString defaultStyleName; +#if defined Q_OS_WIN && QT_VERSION >= QT_VERSION_CHECK(6, 8, 1) + // windows11 style works on Windows 10 too if the right font is available + if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows11) + defaultStyleName = "windows11"; +#endif + // Convenient way to set a default style but still allow the user to customize it + if (!defaultStyleName.isEmpty() && qEnvironmentVariableIsEmpty("QT_STYLE_OVERRIDE")) + qputenv("QT_STYLE_OVERRIDE", defaultStyleName.toLocal8Bit()); + QVApplication app(argc, argv); +#if defined Q_OS_WIN && QT_VERSION >= QT_VERSION_CHECK(6, 8, 1) + // For windows11 style on Windows 10, make sure we have the font it needs, otherwise change style + if (QOperatingSystemVersion::current() < QOperatingSystemVersion::Windows11 && + QApplication::style()->name() == "windows11" && + !QFontDatabase::families().contains("Segoe Fluent Icons")) + { + const QString fontPath = QDir(QApplication::applicationDirPath()).filePath("fonts/Segoe Fluent Icons.ttf"); + if (QFile::exists(fontPath)) + QFontDatabase::addApplicationFont(fontPath); + else + QApplication::setStyle("windowsvista"); + } +#endif + QCommandLineParser parser; parser.addHelpOption(); parser.addVersionOption();