Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-53741

QPainter::combinedTransform returns unexpected value when High DPI scaling is used

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.4.0, 5.6.0
    • GUI: Painting
    • 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.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            sorvig Morten Sørvig
            roblefebvre Rob Lefebvre
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes