support high dpi

This commit is contained in:
wangxd 2023-11-17 15:13:17 +08:00
parent ea55d37104
commit 7ea8d7a5ba
1 changed files with 16 additions and 5 deletions

View File

@ -120,11 +120,18 @@ class MyApplication : public QApplication
int main(int argc, char *argv[])
{
//可以防止某些屏幕下的字体拥挤重叠问题。暂时屏蔽不使用qt方法使用windows自带方案
// 发现windows自带方案模糊。//发现下面打开后在win10上反而效果不好界面会变得很大默认还是不开启的好。
//QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
//QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
//QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::RoundPreferFloor);
#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
#ifdef Q_OS_WIN
HDC hdc = CreateDC(L"display", NULL, NULL, NULL);
int ndpi = GetDeviceCaps(hdc, LOGPIXELSY);
qputenv("QT_SCALE_FACTOR", QString::number(ndpi / 96.0).toUtf8());
#endif // Q_OS_WIN
#endif
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
#ifdef Q_OS_MAC
MyApplication a(argc, argv);
@ -132,6 +139,10 @@ int main(int argc, char *argv[])
QApplication a(argc, argv);
#endif
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
a.setAttribute(Qt::AA_UseHighDpiPixmaps);
#endif
//不能开启,开启后相对路径打开文件失败
//QDir::setCurrent(QCoreApplication::applicationDirPath());