From bbc830ce3e9933767924452d416923a4fa6fa5da Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 5 Feb 2016 12:22:26 +0100 Subject: [PATCH] QIcon::fromTheme(): add support for absolute paths. This allows methods that return an icon name, to sometimes also return an icon full path (e.g. because the icon was dynamically generated and stored into a local cache on disk) Change-Id: Ib01c3955f4b64236463846241d9814b2d0686634 Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/gui/image/qicon.cpp | 3 +++ tests/auto/gui/image/qicon/tst_qicon.cpp | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 2b148383b0..620cbde25d 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -51,6 +51,7 @@ #include "qvariant.h" #include "qcache.h" #include "qdebug.h" +#include "qdir.h" #include "qpalette.h" #include "qmath.h" @@ -1171,6 +1172,8 @@ QIcon QIcon::fromTheme(const QString &name) if (qtIconCache()->contains(name)) { icon = *qtIconCache()->object(name); + } else if (QDir::isAbsolutePath(name)) { + return QIcon(name); } else { QPlatformTheme * const platformTheme = QGuiApplicationPrivate::platformTheme(); bool hasUserTheme = QIconLoader::instance()->hasUserTheme(); diff --git a/tests/auto/gui/image/qicon/tst_qicon.cpp b/tests/auto/gui/image/qicon/tst_qicon.cpp index ff88b62c32..079b14a64e 100644 --- a/tests/auto/gui/image/qicon/tst_qicon.cpp +++ b/tests/auto/gui/image/qicon/tst_qicon.cpp @@ -642,6 +642,10 @@ void tst_QIcon::fromTheme() QIcon::setThemeName(""); abIcon = QIcon::fromTheme("address-book-new"); QVERIFY(abIcon.isNull()); + + // Passing a full path to fromTheme is not very useful, but should work anyway + QIcon fullPathIcon = QIcon::fromTheme(m_pngImageFileName); + QVERIFY(!fullPathIcon.isNull()); } void tst_QIcon::fromThemeCache()