1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| struct DpiCompatible { static double GetDpiScale() { double dDpi = 1.0; HDC desktopDc = GetDC(NULL); float horizontalDPI = GetDeviceCaps(desktopDc, LOGPIXELSX); float verticalDPI = GetDeviceCaps(desktopDc, LOGPIXELSY); int dpi = (horizontalDPI + verticalDPI) / 2; dDpi = 1 + ((dpi - 96) / 24) * 0.25; if (dDpi < 1) { dDpi = 1; } ReleaseDC(NULL, desktopDc); return dDpi; } static void InitQtDPICompatible() { SetProcessDPIAware(); qputenv("QT_SCALE_FACTOR", QString::number(GetDpiScale()).toLatin1()); } };
|