Update on standard icons in Qt

Published Tuesday October 27th, 2009
16 Comments on Update on standard icons in Qt
Posted in KDE, Qt

Someone sent me an e-mail asking what happened to the freedesktop icons I blogged about back in february so I realized I should probably write a followup. I’m happy to say that it has been merged into Qt 4.6 for some time already. If you look up the documentation for QIcon, you will find a new function QIcon::fromTheme(…) which essentially does what QtIconLoader::icon(…) did. Meaning Qt applications can now make use of the icon themes that KDE and GNOME ship with and use by default.

Since freedesktop icon themes only come as standard on X11 based desktops, you cannot use themed icons on other platforms such as Windows and Mac directly. This will simply return the fallback icon you provide. Allowing this would have forced us to decide on a standard icon theme as well as bloat the application by an extra few megabytes that many applications do not need. Instead we decided to leave this choice entirely up to the developer by making it possible to bundle themes such as Oxygen or Tango as part of the application resources and pointing to it using QIcon::setThemeName(…) instead.

This should make those pure Qt applications look a lot more integrated into the X11 desktop! Among other things, our trusty old Assistant client was modified to use the theme icons:

assistant

Screenshot showing of Assistant running on GNOME in 4.6.

Assistant KDE

Here is the same application running on KDE 4.

Do you like this? Share it
Share on LinkedInGoogle+Share on FacebookTweet about this on Twitter

Posted in KDE, Qt

16 comments

SABROG says:

Can i use themes and icons for commercial application on Qt? They all in GPL license?

Jens says:

SABROG: Yes you can. When you use standard icons on X11 you will load them dynamically from the computer using the current system configuration. This should not have any impact on the licensing of your application. This is no different to what you are already doing with current folder and file icons in Qt.

The question really only becomes relevant if you bundle a theme together with your application. (which is really not recommended on X11 as it beats the purpose of standard icons) In this case you have to read the license that the theme comes with. For instance the Oxygen has a few restrictions as listed in the legal part of their site:
http://www.oxygen-icons.org/?page_id=4 while the Tango project recently became public domain, meaning you can essentially do whatever you want with it.

GNOME user says:

Great development. We need look-like-native qt apps in GNOME/Ubuntu ;] does it suports also icons inside menu and context menu?

Jens says:

GNOME user: Certainly, the icons are normal scalable QIcons that adjust to your desktop settings dynamically. You use them wherever you would place normal Qt icons. Keep in mind that in the new GNOME 2.28, menus no longer have icons by default and Qt will respect. If you want icons to show in menus on the next iteration of GNOME/Ubuntu you will need to specifically enable this in the Appearance/Interface tab or force it by explicitly setting the iconsVisibleInMenu property on QAction.

EuroElessar says:

It’s great possibility! But what about fallbacks? If there is no icon “input-mouse-usb” in theme will IconLoader engine try to load icon “input-mouse”?

Jens says:

The fallbacks for devices are part of the naming convention not the icon lookup itself. But QIcon::fromTheme has a second and optional fallback argument that makes it possible to do this :

QIcon genericIcon = QIcon::fromTheme(“input-mouse”); // or alternatively use a pixmap
QIcon usbMouseIcon = QIcon::fromTheme(“input-mouse-usb”, genericIcon);
QIcon ps2MouseIcon = QIcon::fromTheme(“input-mouse-ps2”, genericIcon);

If you do not pass a fallback the function will simply return a null icon.

tatami says:

Good job.

Is there a function to get a icon’s name in a icon theme directory in Qt, by default ?

tatami says:

Sorry, I posted wrong question. The question I wanted to post is as follows.

Is there a function to get a icon’s names list in a icon theme directory from in Qt, by default ?

tatami says:

Sorry, The question I wanted to post is as follows.

Is there a function to get a icon’s names list in a icon theme directory in Qt, by default ?

EuroElessar says:

Thanks, Jens.
By the way, there is well known fact that there are animated icons in freedesktop.org standart… so are there any plans for supporting of them?

EuroElessar says:

And also I hope the last question: will be there any api for getting paths to icons? i.e. path to input-mouse-usb.png with size 32×32 or to svg one.

Pat says:

Now if only that font hinting bug that gets triggered when ttf-arphic-uming is installed were fixed…

Alessandro says:

@Pat: Which bug ID on http://bugreports.qt.nokia.com/ is the one you mean?

Pat says:

This used to be in the Qt bug database, though I can’t find it. I have it noted that:

http://ubuntuforums.org/showthread.php?t=672272

had a link to the bug, but that URL is dead now.

Anyway, it seems to be worked around in most distributions. Whereas ttf-arphic-uming used to set:

false
true
false

They now set:

true

Whereas the former magically propagated to all fonts under Qt, the latter works, because it only applies to fonts with embedded bitmap information. Also, in recent versions, upstream has turned on the embeddedbitmap flag to true by default for all fonts.

Pat says:

Hm. It stripped out all of the fontconfig XML. I’ll type it out differently.

edit name=antialias -> false
edit name=hinting -> true
edit name=autohint -> false

Now it’s just:

edit name=embeddedbitmap -> true

Julien says:

That is such a cool feature !!!! Thanks !
How about integrating it into the Designer (and integrating the QStyle::StandardPixmap as well 🙂 ) ?

Commenting closed.

Get started today with Qt Download now