概述
通过比例系数来实现高分屏适配,软件的每个UI组件尺寸都要乘以比例系数,以达到适配高分辨率的目的
实现
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| win32:{ QT += winextras }
#include <QApplication> #ifdef Q_OS_WIN #include "windows.h" #endif
void getWindowScaleFactor() { double scaleFactor = 1.0; #ifdef Q_OS_WIN int nWidth = GetSystemMetrics(SM_CXSCREEN); #else QRectF rect = QApplication::desktop()->screenGeometry(); int nWidth = rect.width(); #endif
if(nWidth >= 3840 ) { scaleFactor = 2.0; } else if(nWidth < 3840 && nWidth > 1366 ) { scaleFactor = 1.0; } else if(nWidth <= 1366 && nWidth > 800 ) { scaleFactor = 0.8; } else if(nWidth <= 800) { scaleFactor = 0.5; }
QApplication::instance()->setProperty("scalefactor", dScaleFactor); return; }
|