制作网站的模板下载软件,企业做网站公司怎么样,排行榜前十名,怎么做服装网站一、根据DPI实现动态调整控件大小#xff08;三种方式#xff09;
1、QT支持高DPI#xff08;针对整个进程中所有的UI#xff09;
// main函数中
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling)tips#xff1a;#xff08;1#xff09;如果不想全局设置三种方式
1、QT支持高DPI针对整个进程中所有的UI
// main函数中
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling)tips1如果不想全局设置可以使用下面两种方式进行单独设置。2如果想有的窗口使用系统高DPI缩放有的窗口保持DPI就需要设置该属性并修改QT源码增加接口来判断某个窗口是否需要高DPI自动缩放
2、存在该头文件QtWidgets/private/qstylehelper_p.h
#include QtWidgets/private/qstylehelper_p.hqreal KStyle::dpiScaled(qreal value)
{
#ifdef Q_OS_MAC// On mac the DPI is always 72 so we should not scale itreturn value;
#elsereturn QStyleHelper::dpiScaled(value);
#endif
}3、不存在该头文件QtWidgets/private/qstylehelper_p.h自己实现
#include QScreenqreal KStyle::dpiScaled(qreal value)
{
#ifdef Q_OS_MAC// On mac the DPI is always 72 so we should not scale itreturn value;
#elseqreal dpi QGuiApplication::primaryScreen()-logicalDotsPerInch(); static const qreal scale qreal(dpi) / 96.0;return value * scale;
#endif
}二、使用示例
ui-btnClose-setFixedHeight(dpiScaled(ui-btnClose-minimumHeight()));