[Development] High-dpi Qt best practices

Sorvig Morten Morten.Sorvig at digia.com
Thu Oct 11 10:16:13 CEST 2012


On Oct 11, 2012, at 9:36 AM, Samuel Rødal <samuel.rodal at digia.com>
 wrote:

> On 10/11/2012 08:23 AM, Ziller Eike wrote:
>> 
>> On 10.10.2012, at 16:56, Olivier Goffart wrote:
>> 
>> If you'd now be able to change the unit in Qt to "pixel metrics" for
>> certain widgets (and optionally sub widgets) where you really want to
>> take advantage of each and every pixel in e.g. painting code, then every
>> case would be covered. (And you could decide to do what you suggest.)
> 
> Agreed, it definitely needs to be possible to turn off the 2x2 scaling 
> for widgets that _do_ care about individual device pixels.

How about:

QPainter p(this);
qreal scaleFactor = this->windowHandle()->dpiScaleFactor();
p.scale(1.0 / scaleFactor, 1.0 / scaleFactor);
QRect pxelRect(QPoint(0, 0), this->size() * scaleFactor);
// paint within pxelRect

A bit cumbersome, but it is a special case. Also, we need to make sure the call to scale cancel out properly with the 2x device scale and that the final transform has a proper QTransform::TransformationType .

Morten






More information about the Development mailing list