Widgets: pass dpr to QIcon::pixmap()

Replace the last occourences of QIcon::pixmap() which do not pass the
current devicePixelRatio with the correct calls.

Pick-to: 6.9
Change-Id: I440944f784a991a88a8c6bb42e4c79f112bab8f6
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Christian Ehrlicher 2025-04-19 13:59:14 +02:00
parent 83d964ea70
commit 78ae4177fa
3 changed files with 7 additions and 4 deletions

View File

@ -197,8 +197,11 @@ void QUrlModel::setUrl(const QModelIndex &index, const QUrl &url, const QModelIn
// Make sure that we have at least 32x32 images
const QSize size = newIcon.actualSize(QSize(32,32));
if (size.width() < 32) {
QPixmap smallPixmap = newIcon.pixmap(QSize(32, 32));
newIcon.addPixmap(smallPixmap.scaledToWidth(32, Qt::SmoothTransformation));
const auto widget = qobject_cast<QWidget *>(parent());
const auto dpr = widget ? widget->devicePixelRatio() : qApp->devicePixelRatio();
const auto smallPixmap = newIcon.pixmap(QSize(32, 32), dpr);
const auto newPixmap = smallPixmap.scaledToWidth(32 * dpr, Qt::SmoothTransformation);
newIcon.addPixmap(newPixmap);
}
}

View File

@ -251,7 +251,7 @@ void QVistaHelper::drawTitleBar(QPainter *painter)
const QPoint pos(origin.x() + iconLeft, origin.y() + verticalCenter - size / 2);
const QPoint posDp = pos * QVistaHelper::m_devicePixelRatio;
const HICON hIcon = qt_pixmapToWinHICON(windowIcon.pixmap(size * QVistaHelper::m_devicePixelRatio));
const HICON hIcon = qt_pixmapToWinHICON(windowIcon.pixmap(QSize(size, size), QVistaHelper::m_devicePixelRatio));
DrawIconEx(hdc, posDp.x(), posDp.y(), hIcon, 0, 0, 0, NULL, DI_NORMAL | DI_COMPAT);
DestroyIcon(hIcon);
}

View File

@ -479,7 +479,7 @@ void ControlLabel::updateWindowIcon()
if (menuIcon.isNull())
menuIcon = style()->standardIcon(QStyle::SP_TitleBarMenuButton, nullptr, parentWidget());
const int iconSize = style()->pixelMetric(QStyle::PM_TitleBarButtonIconSize, nullptr, parentWidget());
label = menuIcon.pixmap(iconSize);
label = menuIcon.pixmap(QSize(iconSize, iconSize), devicePixelRatio());
update();
}