QIcon: Fix that HiDPI image was not found with QRC alias
When using images in QRC and giving the 1x and 2x image files respective aliases but without any file extension (for example 'myimage' and 'myimage@2x'), then QIcon would fail to find the 2x variant. Task-number: QTBUG-44049 Change-Id: I400bf6d22aeefe0aa351c68e473bf24ac2a36471 Reviewed-by: Morten Johan Sørvig <morten.sorvig@theqtcompany.com>
This commit is contained in:
parent
6246e142a4
commit
4805714b0f
@ -1026,15 +1026,15 @@ void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State
|
|||||||
// Check if a "@2x" file exists and add it.
|
// Check if a "@2x" file exists and add it.
|
||||||
static bool disable2xImageLoading = !qgetenv("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING").isEmpty();
|
static bool disable2xImageLoading = !qgetenv("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING").isEmpty();
|
||||||
if (!disable2xImageLoading && qApp->devicePixelRatio() > 1.0) {
|
if (!disable2xImageLoading && qApp->devicePixelRatio() > 1.0) {
|
||||||
int dotIndex = fileName.lastIndexOf(QLatin1Char('.'));
|
|
||||||
if (dotIndex != -1) {
|
|
||||||
QString at2xfileName = fileName;
|
QString at2xfileName = fileName;
|
||||||
|
int dotIndex = fileName.lastIndexOf(QLatin1Char('.'));
|
||||||
|
if (dotIndex == -1) /* no dot */
|
||||||
|
dotIndex = fileName.size(); /* append */
|
||||||
at2xfileName.insert(dotIndex, QStringLiteral("@2x"));
|
at2xfileName.insert(dotIndex, QStringLiteral("@2x"));
|
||||||
if (QFile::exists(at2xfileName))
|
if (QFile::exists(at2xfileName))
|
||||||
d->engine->addFile(at2xfileName, size, mode, state);
|
d->engine->addFile(at2xfileName, size, mode, state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\since 4.5
|
\since 4.5
|
||||||
|
Loading…
Reference in New Issue
Block a user