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

A QIcon with an SVG whose aspect ratio does not match the icon size will have an incorrect pixel ratio set, resulting in the SVG not fitting in the icon correctly and being scaled in an ugly way

    XMLWordPrintable

Details

    • macOS
    • 54f5b8975055f1d48c74efab085acd6338aa1e3c (qt/qtbase/5.14)

    Description

      When an SVG is used in a QIcon, it is rendered to fit the icon size, and the scaling is done to preserve the aspect ratio of the SVG (in QSvgIconEngine::pixmap). However, if this scaling was not 1:1, i.e. the aspect ratio of the SVG did not match that of the icon, the resulting pixmap will be given a fractional device pixel ratio, which has two unfortunate effects:

      1. It can cause the rendered SVG to no longer fit within the icon's bounds
      2. As a pixmap scaling, rather than a vector scaling, it causes unpleasant visual artifacts.

      This pixel ratio is calculated in QIconPrivate::pixmapDevicePixelRatio.

      The attached test app demonstrates the problem. In it, I have a simple SVG with some text with width 357 and height 100. This is rendered in a square QIcon with height and width both equal to 375. After the pixel ratio is set, the SVG ends up far too big for the icon, and also the scaled-up text looks ugly. I've attached a screenshot demonstrating this.

      Note that because QIconPrivate::pixmapDevicePixelRatio returns 1.0 if the input device pixel ratio is 1.0, you only see this problem on a high-DPI display (such as the retina screen on my Mac Book Pro on which I took the screenshots). I don't think it's related to QTBUG-70256 however, as there is no viewBox set on the very simple SVG file in this test case.

      Attachments

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

        Activity

          People

            vgt Eirik Aavitsland
            jlarcombe James Larcombe
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes