QIcon::fromTheme on non linux platforms

Albert Astals Cid aacid at kde.org
Sun Dec 14 00:37:47 GMT 2014


El Dimarts, 9 de desembre de 2014, a les 20:34:23, Jeremy Whiting va escriure:
> Hey all,
> 
> In looking into building some kde applications on windows and mac besides
> linux I've come across a minor hiccup. In many applications and frameworks
> possibly we use QIcon::fromTheme to get icons from a named icon. This is
> even recommended in the kf5 porting notes, however on non linux platforms
> we hit a couple of issues. QIcon::fromTheme's documentation says it's not
> meant to work on non linux platforms or if we want it to work there we need
> to install icons into some theme path, add the theme to the application's
> themeSearchPaths and set the name with setThemeName.
> 
> For kde on windows this is ok since the qt built with the emerge tool is
> patched to set the theme name to "oxygen" however it's not ideal and
> doesn't act the same as on linux itself where oxygen is the icon theme but
> hicolor is a fallback (and there could be others from what I gather besides
> the oxygen theme itself). All the ecm_install_icons calls in kdeedu
> applications that I saw install into hicolor theme, or don't set a theme
> and end up in hicolor by default. So the question then becomes what's the
> correct/best way to get this functionality on non linux platforms? Is
> QIcon::fromTheme something that comes from the platform plugin or do we
> need to use patched Qt on those platforms to support getting the icons our
> applications need?

The *correct* way would be having a QPlatformTheme and reimplementing 
QPlatformTheme::SystemIconThemeName QPlatformTheme::IconThemeSearchPaths and 
QPlatformTheme::SystemIconFallbackThemeName correctly.

Now, you can achieve the same effect with patching the Qt if you have access 
to that and don't have to worry about making sure the platform theme loads 
(taht is not always obvious).

Now onto your problem, oxygen inherits hicolor (as per specified in its 
index.theme file) so if the index.theme file is being correctly found, it 
should return hicolor icons even if the theme name is hardcoded to "oxygen".

See QIconTheme::QIconTheme and QIconLoader::findIconHelper. There's basically 
nothing Unix specific in QIcon::fromTheme, only that the paths/theme names for 
it to work are not set, if you set them either via patching or QPT it should 
just work.

Cheers,
  Albert

> 
> BR,
> Jeremy





More information about the kde-core-devel mailing list