[Development] XDG icon theme support

Ruslan Nigmatullin euroelessar at yandex.ru
Sat Mar 29 02:32:10 CET 2014

Hi friends,

Current Qt's implementation of QIcon::fromTheme violates xdg icon naming specification ( http://standards.freedesktop.org/icon-naming-spec/icon-naming-spec-latest.html ).
By specification if icon "drive-removable-media-usb" is not found implementation should fallback to "drive-removable-media" and so on until the icon is not found. If icon is not found at this theme is should make lookup at parents' themes.

> The dash “-” character is used to separate levels of specificity
> in icon names, for all contexts other than MimeTypes. For instance,
> we use “input-mouse” as the generic item for all mouse devices,
> and we use “input-mouse-usb” for a USB mouse device. However,
> if the more specific item does not exist in the current theme, and
> does exist in a parent theme, the generic icon from the current
> theme is preferred, in order to keep consistent style. 

For example this makes possible to use most of icons provided by Oxygen theme (which has really specific icons like network-wireless-connected-50) with more generic fallbacks under with other themes (like network-wireless).

In C++ the possible workaround is to use something like QIcon::fromTheme("network-wireless-connected-50", QIcon::fromTheme("network-wireless-connected". QIcon::fromTheme("network-wireless", QIcon::fromTheme("network")))) but it's not the most efficient and elegant solution. And it still violates the specification in the case if:
1. Current theme contains icons "network-wireless-connected-50" and "network-wireless"
2. Parent's theme contains icons "network-wireless-connected-50"

By specification current theme's "network-wireless" icon should be choosed, but not the parent's "network-wireless-connected-50" for better user experience as current implementation does.

Also the pain starts if one would decide to change the icons theme at runtime (i.e. by changing KDE's settings). Original icon's names are already lost at this point (as we iterated by prefixes until the valid icon) so invalid or no icon will be chosen after the theme change.

In QML the situation is even worse, it's not possible at all to determine from QML if icon is correct one so it's totally impossible to do anything and it ruins my life :(

Was this done specially or it should be considered as a bug? If the first option what was the main idea?

I would like to implement the correct behavior by the following changes:
1. Never return fallback from QIcon::fromTheme if it is null. So it will be possible to show the icon once the correct theme will be shown.
2. Change the logic of QIconLoader::findIconHelper to fit the specification by adding check for fallback icons.

If the changes will be done and accepted is there any hope to have them in Qt 5.2.* (so it will come once to Ubuntu Trusty)?

Ruslan Nigmatullin

More information about the Development mailing list