Update on standard icons in Qt

Posted by Jens Bache-Wiig on October 27, 2009 · 16 comments

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.

QShare(this)

Possibly related posts:

  1. Update on the jumping Norwegian guy and the Qt Web Runtime project
  2. Qt Contributors’ Summit – Update
  3. Important Update on Qt Mobility 1.1.0 Beta Package

16 comments

1 SABROG October 27, 2009 at 5:55 pm
 

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

2 Jens October 27, 2009 at 6:25 pm
 

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.

3 GNOME user October 27, 2009 at 11:19 pm
 

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

4 Jens October 28, 2009 at 10:37 am
 

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.

5 EuroElessar October 28, 2009 at 9:14 pm
 

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”?

6 Jens October 28, 2009 at 9:47 pm
 

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.

7 tatami October 29, 2009 at 3:09 am
 

Good job.

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

8 tatami October 29, 2009 at 3:17 am
 

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 ?

9 tatami October 29, 2009 at 3:42 am
 

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 ?

10 EuroElessar October 29, 2009 at 7:40 am
 

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?

11 EuroElessar October 29, 2009 at 1:45 pm
 

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.

12 Pat October 30, 2009 at 4:25 pm
 

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

13 Alessandro October 31, 2009 at 11:57 am
 

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

14 Pat November 3, 2009 at 11:11 pm
 

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.

15 Pat November 3, 2009 at 11:13 pm
 

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

16 Julien November 11, 2009 at 3:48 pm
 

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

Comments on this entry are closed.

Previous post:

Next post: