Skip to content

Commit

Permalink
Use windows11 style on Windows 10
Browse files Browse the repository at this point in the history
  • Loading branch information
jdpurcell committed Dec 8, 2024
1 parent 751761a commit 350e671
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions dist/scripts/windeployqt.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Binary file added dist/win/fonts/Segoe Fluent Icons.ttf
Binary file not shown.
26 changes: 26 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,41 @@
#include "qvwin32functions.h"

#include <QCommandLineParser>
#include <QFontDatabase>

int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
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();
Expand Down

0 comments on commit 350e671

Please sign in to comment.