HiDPI: Select most fitting pixel ratio when painting QIcon

There is a way to select a better pixel ratio when the QPainter has a
valid pointer to a QPaintDevice than simply getting the global app
pixel ratio.

Change-Id: I8f89fd01094bbac7a01a83be89991730b0fa6597
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
This commit is contained in:
Florian Korsakissok 2019-11-13 13:46:24 +01:00 committed by Thorbjørn Lund Martsum
parent 54f5b89750
commit 61def1f6cd

View File

@ -190,7 +190,12 @@ QPixmapIconEngine::~QPixmapIconEngine()
void QPixmapIconEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state)
{
QSize pixmapSize = rect.size() * qt_effective_device_pixel_ratio(0);
qreal dpr = 1.0;
if (QCoreApplication::testAttribute(Qt::AA_UseHighDpiPixmaps)) {
auto paintDevice = painter->device();
dpr = paintDevice ? paintDevice->devicePixelRatioF() : qApp->devicePixelRatio();
}
const QSize pixmapSize = rect.size() * dpr;
QPixmap px = pixmap(pixmapSize, mode, state);
painter->drawPixmap(rect, px);
}