Fix: QIcon high dpi scaling when aspect ratio differs
When an icon engine is asked to produce a pixmap scaled to a certain size, it may return one with a different aspect ratio than requested. In particular, an SVG will use its own aspect ratio, as it should. QIcon's DPR calculation would break down in this case, resulting in ugly scaling. Fixes: QTBUG-79371 Change-Id: Id97049259dcee1a2980474250ef1163be5639085 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
9f48f1ebc2
commit
54f5b89750
@ -165,6 +165,11 @@ QIconPrivate::QIconPrivate(QIconEngine *e)
|
||||
qreal QIconPrivate::pixmapDevicePixelRatio(qreal displayDevicePixelRatio, const QSize &requestedSize, const QSize &actualSize)
|
||||
{
|
||||
QSize targetSize = requestedSize * displayDevicePixelRatio;
|
||||
if ((actualSize.width() == targetSize.width() && actualSize.height() <= targetSize.height()) ||
|
||||
(actualSize.width() <= targetSize.width() && actualSize.height() == targetSize.height())) {
|
||||
// Correctly scaled for dpr, just having different aspect ratio
|
||||
return displayDevicePixelRatio;
|
||||
}
|
||||
qreal scale = 0.5 * (qreal(actualSize.width()) / qreal(targetSize.width()) +
|
||||
qreal(actualSize.height() / qreal(targetSize.height())));
|
||||
return qMax(qreal(1.0), displayDevicePixelRatio *scale);
|
||||
|
Loading…
x
Reference in New Issue
Block a user