Qt获得windows屏幕的缩放倍数的方法

1.使用Qt的封装函数:

#include 

QScreen *screen      = qApp->primaryScreen();
qreal    dotsPerInch = screen->logicalDotsPerInch(); /* 单位内的点数 */
double screenScale = (double)dotsPerInch / 96.0;

2.使用c++函数:需要添加的系统库为 :Gdi32.lib User32.lib


#include 
#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;

你可能感兴趣的:(qt,windows,开发语言)