Details
-
Bug
-
Resolution: Done
-
P3: Somewhat important
-
5.12.3, 5.14.0 Beta 1
-
None
-
-
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:
- It can cause the rendered SVG to no longer fit within the icon's bounds
- 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.