简体   繁体   English

如何解释QFontMetrics结果?

[英]How to interpret QFontMetrics results?

I have a problem making sense of the values I get from QFontMetrics 我在理解从QFontMetrics获得的值时遇到QFontMetrics

// 43 characters        0123456789012345678901234567890123456789012
static const QString s("The quick brown fox jumps over the lazy dog");
// Hint: basically returns w->fontMetrics(); with w being my main application window
const QFontMetrics fm = CGuiUtility::currentFontMetrics();
const int w = fm.width(s);
const int h = fm.height();
return QSize(w, h);

With the following screen resolutions I get: 使用以下屏幕分辨率,我得到:

  1. ) 1920/1080: 256/16 )1920/1080:256/16
  2. ) 3840/2160: 178/10 hi DPI support qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1") )3840/2160:178/10喜好DPI支持qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1")
  3. ) 3840/2160: 536/32 no hi DPI support )3840/2160:536/32不支持DPI

My understanding is that I do get pixel width/height. 我的理解是,我确实获得了像素的宽度/高度。 I wonder why I get a so much smaller height with a hires resolution (see 2). 我想知道为什么我的租用分辨率要小得多(参见2)。 I would rather expect it the other way around - using more pixels. 我宁愿反过来-使用更多像素。

What I can see is that there is (almost) factor 2 between 1 and 3, which makes sense. 我看到的是(几乎)因子2在1和3之间,这是有道理的。 But then (using 3, no DPI support) the UI is unreadable (too small because of hi DPI screen). 但是,然后(使用3,没有DPI支持)UI无法读取(由于显示DPI屏幕太小,所以太小)。 So how does 2 fit in, which has some odd results. 那么2如何拟合,结果有些奇怪。

Is anybody able to give a hint on the interpretation of those values? 有人能暗示这些价值观的解释吗?

Remark: Related to Style sheets / Qt Designer support for high dpi screens? 备注:与样式表/ Qt Designer对高dpi屏幕的支持有关吗? What I try to find is a reasonable width/height for my UI window on different resolutions/platforms 我试图找到的是在不同分辨率/平台上的UI窗口的合理宽度/高度


Good comments, I see. 好的评论,我明白了。 With hi-dpi Qt scales 1:3 using a "virtual screen" of 1280/780. 对于高dpi的Qt,使用1280/780的“虚拟屏幕”可按1:3缩放比例。 I wonder if I can adjust that pixel ratio manually. 我想知道是否可以手动调整像素比例。 In my very case it happens by setting qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1") . 就我而言,这是通过设置qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1") Is there a chance to set it to 2:1? 是否有机会将其设置为2:1?

  1. ) "Desktop w1920 w1080 - ratio: 1 | 80 chars: w560 h16 | 43 chars: w256 h16" )“台式机w1920 w1080-比率:1 | 80个字符:w560 h16 | 43个字符:w256 h16”
  2. ) "Desktop w1280 w720 hi DPI ratio: 3 | 80 chars: w400 h10 | 43 chars: w178 h10" )“台式机w1280 w720嗨DPI比率:3 | 80个字符:w400 h10 | 43个字符:w178 h10”
  3. ) "Desktop w3840 w2160 - ratio: 1 | 80 chars: w1200 h32 | 43 chars: w536 h32" )“台式机w3840 w2160-比率:1 | 80个字符:w1200 h32 | 43个字符:w536 h32”

Based on the hints of AlexanderVX and SteackOverflow it is clear now. 根据AlexanderVX和SteackOverflow的提示,现在很清楚。

  1. "Desktop w1920 w1080 - ratio: 1 | 80 chars: w560 h16 | 43 chars: w256 h16" “台式机w1920 w1080-比率:1 | 80个字符:w560 h16 | 43个字符:w256 h16”
  2. "Desktop w1280 w720 hi DPI ratio: 3 | 80 chars: w400 h10 | 43 chars: w178 h10" “台式机w1280 w720嗨DPI比率:3 | 80个字符:w400 h10 | 43个字符:w178 h10”
  3. "Desktop w3840 w2160 - ratio: 1 | 80 chars: w1200 h32 | 43 chars: w536 h32" “台式机w3840 w2160-比率:1 | 80个字符:w1200 h32 | 43个字符:w536 h32”

Therefor I close the topiy 因此我关闭了顶部

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM