Added UI scale factor logic.

This commit is contained in:
Andrei Smirnov 2021-09-02 09:09:06 +03:00 committed by Michał
parent 2bf1bfb30d
commit c38a360e74
2 changed files with 10 additions and 2 deletions

View File

@ -60,7 +60,7 @@ DOS_API void DOS_CALL dos_qcoreapplication_process_events(DosQEventLoopProcessEv
/// \brief Force the event loop to spin and process the given events until no more available or timed out /// \brief Force the event loop to spin and process the given events until no more available or timed out
DOS_API void DOS_CALL dos_qcoreapplication_process_events_timed(DosQEventLoopProcessEventFlag flags, int ms); DOS_API void DOS_CALL dos_qcoreapplication_process_events_timed(DosQEventLoopProcessEventFlag flags, int ms);
DOS_API void DOS_CALL dos_qapplication_enable_hdpi(void); DOS_API void DOS_CALL dos_qapplication_enable_hdpi(const char *uiScaleFilePath);
DOS_API void DOS_CALL dos_qapplication_initialize_opengl(void); DOS_API void DOS_CALL dos_qapplication_initialize_opengl(void);

View File

@ -26,6 +26,7 @@
#include <QtCore/QModelIndex> #include <QtCore/QModelIndex>
#include <QtCore/QHash> #include <QtCore/QHash>
#include <QtCore/QResource> #include <QtCore/QResource>
#include <QtCore/QFile>
#include <QtNetwork/QNetworkAccessManager> #include <QtNetwork/QNetworkAccessManager>
#include <QtNetwork/QNetworkDiskCache> #include <QtNetwork/QNetworkDiskCache>
#include <QtNetwork/QNetworkConfigurationManager> #include <QtNetwork/QNetworkConfigurationManager>
@ -122,9 +123,16 @@ char *dos_qcoreapplication_application_dir_path()
return convert_to_cstring(QCoreApplication::applicationDirPath()); return convert_to_cstring(QCoreApplication::applicationDirPath());
} }
void dos_qapplication_enable_hdpi() void dos_qapplication_enable_hdpi(const char *uiScaleFilePath)
{ {
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
QFile scaleFile(QString::fromUtf8(uiScaleFilePath));
if (scaleFile.open(QIODevice::ReadOnly)) {
const auto scale = scaleFile.readAll();
qputenv("QT_SCALE_FACTOR", scale);
}
} }
void dos_qapplication_initialize_opengl() void dos_qapplication_initialize_opengl()