Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.4.0, 5.6.0
-
None
-
Windows 10
Description
QPainter::combinedTransform() returns a transform which includes the high DPI scaling. A typical use for this function is to convert coordinates to pixels (QTransform::map), clear the painter's transform, then draw in pixel coordinates. In High DPI, even after the transform is cleared, the painter still uses the High DPI scaling. Here's typical code:
QTransform transform = painter->combinedTransform();
painter->setTransform(QTransform());
// Convert world coordinates to pixel
transform.map(worldX, worldY, &devX, &devY);
// Now, draw something in PIXEL sizes around devX, devY, like a handle
painter->drawRect(devX-1, devY-1, devX+1, devX+1);
This code no longer works when high dpi scaling is active: devX and devY are in physical pixels, but the drawing functions expect logical (high DPI scaled) pixels.
The transform must be modified to work as expected:
QTransform transform = painter->combinedTransform();
transform /= painter->device()->devicePixelRatio();
It seems that the combinedTransform() should only return the combined world and view transformations, not including the high DPI scale factor.