From 65aff4dc422f53faa44e961850cb4f1e4501a8c7 Mon Sep 17 00:00:00 2001 From: Jason Haslam Date: Fri, 2 Oct 2015 11:56:29 -0600 Subject: [PATCH] Fix regression in scaled QLabel on hi-res display. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The change in bc1796f for QTBUG-42503 only works for scaling down pixel-doubled images. Smaller images scale up incorrectly. Fixed by setting the devicePixelRatio of the scaled pixmap to the devicePixelRatio of the label. Also, caching was broken by not accounting for scaling by devicePixelRatio in the condition. Change-Id: I6e1503652e61683a16312c74f46b79d28c880848 Task-number: QTBUG-46846 Reviewed-by: Morten Johan Sørvig --- src/widgets/widgets/qlabel.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/widgets/widgets/qlabel.cpp b/src/widgets/widgets/qlabel.cpp index 55e277026c..a07a964595 100644 --- a/src/widgets/widgets/qlabel.cpp +++ b/src/widgets/widgets/qlabel.cpp @@ -1091,14 +1091,16 @@ void QLabel::paintEvent(QPaintEvent *) if (d->pixmap && !d->pixmap->isNull()) { QPixmap pix; if (d->scaledcontents) { - if (!d->scaledpixmap || d->scaledpixmap->size() != cr.size()) { + QSize scaledSize = cr.size() * devicePixelRatioF(); + if (!d->scaledpixmap || d->scaledpixmap->size() != scaledSize) { if (!d->cachedimage) d->cachedimage = new QImage(d->pixmap->toImage()); delete d->scaledpixmap; QImage scaledImage = - d->cachedimage->scaled(cr.size() * devicePixelRatioF(), + d->cachedimage->scaled(scaledSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); d->scaledpixmap = new QPixmap(QPixmap::fromImage(scaledImage)); + d->scaledpixmap->setDevicePixelRatio(devicePixelRatioF()); } pix = *d->scaledpixmap; } else