[Development] [HiDPI] Rethinking the scaling algorithm

Morten Sorvig Morten.Sorvig at qt.io
Thu Nov 10 10:43:06 CET 2016


> On 8 Nov 2016, at 15:57, Niccolò Belli <darkbasic at linuxsystems.it> wrote:
> 
> Hi,
> My laptop's monitor is a 13" with a 16:9 aspect ratio and a 3200x1800 resolution. As you can see[1] the EDID[2] is perfectly correct.
> QT computes the scaling factor using a formula like this: scaling_factor=qRound(yourDpi/96)
> This is far from ideal in my opinion, because if we want to scale to 96 logical PPI it means that on a 13" 16:9 screen we want to target a 1088x612 logical resolution. In fact qRound(282.42/96) computes a 3x scaling factor for my laptop, which is not a scaling factor that *anybody* would like to have (except maybe my old grandfather with poor eyesight). In fact a logical resolution of *less* than 1088x612 (it's lesser because qRound actually rounded up the value) is too tiny even for a 13" screen and people would prefer a 2x scaling factor instead, which would give you a logical resolution of 1600x900 (instead of an useless 1067x600).
> 
> I have some suggestions to improve the current scaling algorithm:
> 
> 1) Always round down. With your current formula a 145ppi screen gets scaled by a 2x factor, while every other toolkit (GTK3 for example[3]) starts scaling at 192ppi. This is also what people expect and it would return the correct 2x scaling factor for my laptop. So the formula should be scaling_factor=qRoundDown(yourDpi/96)


Hi, thanks for bringing this up. I agree with this point; mathematically correct rounding
may not be the best kind of correct in this case.

In fact a change is already in review:

	https://codereview.qt-project.org/#/c/157174/

This introduces QT_SCALE_FACTOR_ROUNDING_POLICY with the following options:

	Round		   qRound(), as today
	Ceil		   qCeil()
	Floor	           qFloor()
	RoundPreferFloor   Round up for .75 and higher
	PassThrough	   Do not round and allow fractional scale factors

RoundPreferFloor is the new default. Do you think this is sufficient? Adding more options is
possible, as is adding a C++ API if needed. 

Morten


More information about the Development mailing list