Fix double scaling of SVG icons on high DPI screens

On a high-dpi screen and AA_UseHighDpiPixmaps set, QIcon will ask its
engine for a scaled-up pixmap. When the icon has been created from a
theme, the engine is a QIconLoaderEngine. For a SVG icon, that engine
would recursively use QIcon to load the scaled-up pixmap, leading to
double scale-up. Fix by bypassing the QIcon API in the SVG case,
loading the SVG icon directly from the SVG icon engine.

Done-with: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Fixes: QTBUG-73587
Fixes: QTBUG-75039
Change-Id: I7fba02b6454decb5fcbca9c5a092e75954261dfd
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Tor Arne Vestbø 2020-03-10 11:13:59 +01:00 committed by Eirik Aavitsland
parent bcdf49bcc6
commit d8ab719c08

View File

@ -797,8 +797,12 @@ QPixmap ScalableEntry::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State
if (svgIcon.isNull())
svgIcon = QIcon(filename);
// Simply reuse svg icon engine
return svgIcon.pixmap(size, mode, state);
// Bypass QIcon API, as that will scale by device pixel ratio of the
// highest DPR screen since we're not passing on any QWindow.
if (QIconEngine *engine = svgIcon.data_ptr() ? svgIcon.data_ptr()->engine : nullptr)
return engine->pixmap(size, mode, state);
return QPixmap();
}
QPixmap QIconLoaderEngine::pixmap(const QSize &size, QIcon::Mode mode,