1.使用Qt的封装函数:
#include <QScreen>
QScreen *screen = qApp->primaryScreen();
qreal dotsPerInch = screen->logicalDotsPerInch(); /* 单位内的点数 */
double screenScale = (double)dotsPerInch / 96.0;
2.使用c++函数:需要添加的系统库为 :Gdi32.lib User32.lib
#include <windows.h>
#pragma comment (lib,"Gdi32.lib")
#pragma comment (lib,"User32.lib")
HDC hd = GetDC(NULL);
int horDPI = GetDeviceCaps(hd, LOGPIXELSX);//水平缩放倍数
int verticalDPI = GetDeviceCaps(hd, LOGPIXELSY);//垂直缩放倍数
double sceenScale = (double)verticalDPI /96.0;