diff options
author | Christian Ehrlicher <[email protected]> | 2024-11-17 16:26:17 +0100 |
---|---|---|
committer | Christian Ehrlicher <[email protected]> | 2025-03-12 09:29:09 +0100 |
commit | 9684691d51335362665e85ced591cffae3ea5360 (patch) | |
tree | e71ed8bfc49dc380cbf4f60bf69ddaafd5f1df8d | |
parent | b35ea9b974c965c01cd0a8340a7885621e4413ef (diff) |
QIcon: call qt_findAtNxFile for all devicePixelRatios available
QFile::addFile() was searching for '@N' - image file where N corresponds
to the devicePixelRatio of the QGuiApplication. Since we can have more
than one screen, all different devicePixelRatios should be considered.
Pick-to: 6.9
Change-Id: I7c844e163c5b5ca8752d8461139d7abf39c2e8a5
Reviewed-by: Volker Hilsheimer <[email protected]>
-rw-r--r-- | src/gui/image/qicon.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 854e936d6ea..70ddb1f4bc2 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -1188,9 +1188,22 @@ void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State return; // Check if a "@Nx" file exists and add it. - QString atNxFileName = qt_findAtNxFile(fileName, qApp->devicePixelRatio()); - if (atNxFileName != fileName) - d->engine->addFile(atNxFileName, size, mode, state); + QVarLengthArray<int, 4> devicePixelRatios; + const auto screens = qApp->screens(); + for (const auto *screen : screens) { + const auto dpr = qCeil(screen->devicePixelRatio()); // qt_findAtNxFile only supports integer values + if (dpr >= 1 && !devicePixelRatios.contains(dpr)) + devicePixelRatios.push_back(dpr); + } + std::sort(devicePixelRatios.begin(), devicePixelRatios.end(), std::greater<int>()); + qreal sourceDevicePixelRatio = std::numeric_limits<qreal>::max(); + for (const auto dpr : std::as_const(devicePixelRatios)) { + if (dpr >= sourceDevicePixelRatio) + continue; + const QString atNxFileName = qt_findAtNxFile(fileName, dpr, &sourceDevicePixelRatio); + if (atNxFileName != fileName) + d->engine->addFile(atNxFileName, size, mode, state); + } } /*! @@ -2030,6 +2043,8 @@ QDebug operator<<(QDebug dbg, const QIcon &i) QString qt_findAtNxFile(const QString &baseFileName, qreal targetDevicePixelRatio, qreal *sourceDevicePixelRatio) { + if (sourceDevicePixelRatio) + *sourceDevicePixelRatio = 1; if (targetDevicePixelRatio <= 1.0) return baseFileName; |