Freedesktop icons in Qt

Published Friday February 13th, 2009
10 Comments on Freedesktop icons in Qt
Posted in QGtkStyle, Qt, Styles/QGtkStyle, Uncategorized

Qt already provides a set of standard icons. The nice thing about these icons is that they adapt to the current desktop environment. However the current selection of available icons is rather limited, at least compared to what KDE apps have at their disposal through the freedesktop icon specification. Since most of these icons only are available on the X11 platform, we still haven’t decided how to make them available to pure Qt applications such as Designer and Creator. While we are thinking about that, I thought I might as well wrap up the essential code and provide it as a simple convenience class, QtIconLoader, that you can use in your own project. You can find the source code here.

The class currently only provides one static function:

QIcon QtIconLoader::icon(const QString &iconName, const QIcon &fallback = QIcon()).

Usage should be fairly obvious:
new QAction(QtIconLoader::icon(“document-new”), tr(“&New”), this);

The fallback is of course for platform compatibility so you can provide your own masterpiece as a fallback for other platforms, which is probably the icon you are already using.

And since no blog post is complete without some eye candy, I modified our well know textedit example to QtIconLoader:

Here is how it looks running on KDE 4.2:
QTextEdit in KDE

And since we also pick up GNOME settings, this is how it looks when running GNOME:

QTextEdit in GNOME

I’m sure there are bugs. For some reason freedesktop standardized on everything except a convenient way to detect which theme to use, so we need to do some trickery to get to the KDE and GNOME settings. Feel free to report issues and suggestions here.

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

Posted in QGtkStyle, Qt, Styles/QGtkStyle, Uncategorized


Carlos Ortega says:

We want news from a O.S that >90% world use !
We want news of Windows !
Change, we can !

As I remember, Windows doesn’t have an icon theming mechanism. In fact, one Linux geek who was trying Windows for the first time in half a decade described it as “On Linux, your desktop is the appliance. On Windows, each application is an appliance, complete with its own visual style.” (He wasn’t trying to criticize, but I still see that as a downside)

Jens says:

Stephan: Windows do ship with a few libraries containing common icons for files and folders but haven’t made any attempt on standardizing common icons such as cut and edit. We already expose many of those in QStyle::standardIcon but already have to make our own placeholders for icons that does not exist on Windows. On Mac the situation is somewhat similar. To support the freedesktop icon spec on Windows and Mac we would have to bundle a complete icon theme inside QtGui. Perhaps the best way to do this cross-platform is to simply expand on the set of standard icons we have though

alexis.menard says:

Carlos Ortega :
Apply on all platforms.
Even if it’s related to KDE, it globally says that all stuff related to QGraphicsView are better, performance improved and bugs fixed. More than 50% of our bugs are cross platform, we fix one platform, we fix others.
Qt Kinetic, Fully cross platform when it will be release. Since plasma is the only big real test case (with source code), we use it to test things…
Apply on all platforms.

All platforms.

So please read more further than just the title or if there is KDE/Linux in the blog post. We improve ALL platforms every day as much as possible. Some work are platform dependant like this one…it can happen…

Ryan Cuthbertson says:

“You can find the source code here.”
But I can’t. The project seems to be empty. Eg.
$ svn checkout
svn: URL ‘’ doesn’t exist

Is this code available under the commercial licence?

aaron.jamis says:

Yatak ( Yes, another topic about KDE)

Richard says:

I would be great if Qt supported a greater set of standard icons ‘out of the box’ for all platforms.

When quickly prototyping an application, it is a pain to have to design or collect various icons for standard actions such as open, save, cut, copy, paste, print, undo, redo, and so on. A good start would be to refactor the existing Qt code to make all the icons already currently used in Qt such as those from Designer, Assistant, QPrintPreviewDialog, etc immediately available to coders via QStyle::standardIcon or similar.

Michael Hofmann says:

Thanks for the cool project. Could you relicense it under GPL 2 or 3/GPL 2 or later so it can be used in GPL 3 projects?

@Ryan: > Source is available trough svn: svn://

Jens says:

@Richard : I agree, while doing the example above I feel like all those icons belong as part of the core API. That might be better than exposing this functionality directly and sufficient for most people.
@Michael: Thanks for that! It is already be available as GPL 2 and I’m certainly relicensing it under the LGPL once 4.5 has been released.

Jens says:

@Michael: Sorry, I was a bit quick to reply ignoring the “and later” part. ๐Ÿ˜‰ I’ll see if I can change the license. Just used the most restrictive one for now until I have some sort of approval.
Edit : I changed it to use the Qt license which is GPL 2+3 and commercial.

Commenting closed.

Get started today with Qt Download now