From 4805714b0f5d5584fd390067b6c092ca5ee7f482 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Mon, 26 Jan 2015 16:22:48 +0100 Subject: [PATCH] QIcon: Fix that HiDPI image was not found with QRC alias MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/gui/image/qicon.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 6f6bf158c8..86d9c02c6e 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -1026,13 +1026,13 @@ void QIcon::addFile(const QString &fileName, const QSize &size, Mode mode, State // Check if a "@2x" file exists and add it. static bool disable2xImageLoading = !qgetenv("QT_HIGHDPI_DISABLE_2X_IMAGE_LOADING").isEmpty(); if (!disable2xImageLoading && qApp->devicePixelRatio() > 1.0) { + QString at2xfileName = fileName; int dotIndex = fileName.lastIndexOf(QLatin1Char('.')); - if (dotIndex != -1) { - QString at2xfileName = fileName; - at2xfileName.insert(dotIndex, QStringLiteral("@2x")); - if (QFile::exists(at2xfileName)) - d->engine->addFile(at2xfileName, size, mode, state); - } + if (dotIndex == -1) /* no dot */ + dotIndex = fileName.size(); /* append */ + at2xfileName.insert(dotIndex, QStringLiteral("@2x")); + if (QFile::exists(at2xfileName)) + d->engine->addFile(at2xfileName, size, mode, state); } }