[英]Can QFontMetrics account for windows dpi scaling?
I was under the impression that if you do this in your application 我的印象是,如果您在应用程序中执行此操作
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication* app = new QApplication(temp, NULL);
then Fonts gets automatically scaled up on high resolution display. 然后,字体会自动在高分辨率显示器上按比例放大。 Same if you explicitly increase font scaling in Windows 10 (Settings-->System->Custom Scaling).
如果在Windows 10中显式增加字体缩放(设置->系统->自定义缩放),则相同。
However, when running the following code with 100% and then 200% scaling in Windows 10, it does not return doubled size. 但是,在Windows 10中以100%然后200%的比例运行以下代码时,它不会返回加倍的大小。
QFont font = QFont("arial", 10);
QFontMetrics fm(font);
int width = fm.width("abcdefgABCDEFG");
Strangely there is only 1 pixel difference. 奇怪的是只有1个像素的差异。
100% --> width = 108 pixels
200% --> width = 109 pixels
Why is that? 这是为什么? Can I get QFontMetrics to account for Windows scaling?
我可以让QFontMetrics解决Windows扩展问题吗? Or do I need to use Logical / Physical DPI to deduce that font size must be increased by a factor 2?
还是我需要使用逻辑/物理DPI来推断必须将字体大小增加2倍?
Thanks 谢谢
For the proper scaling of custom-drawn items use QScreen::physicalDotPerInch property to realize the scaling coefficient to apply to actual drawings: 为了适当缩放自定义绘制的项目,请使用QScreen :: physicalDotPerInch属性来实现应用于实际图形的缩放系数:
qreal myScale = pScreen->physicalDotPerInch() / constStandardPerInch;
PS The question still needs to be revised. PS问题仍然需要修订。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.