View post

Icon themes for pure Qt applications

Posted by lucidfox.org at

Recently, I went to package the JuffEd text editor for Ubuntu (it’s on REVU now), and I was surprised that it used bundled Tango icons by default. Then I looked at the code and saw that support for XDG icon themes was really hackish, and didn’t work with inherited themes such as gnome-colors flavors.

It’s strange that support for “stock icons” is not in Qt, unlike GTK, but still, I’d like non-KDE Qt applications to support them properly. So, yesterday, I wrote a small library to properly implement the icon theme specification.

If you’re writing a Qt application dealing with icons, there are two classes of note in that library:

  • XdgIconManager keeps the list of themes installed in the system, and returns themes by human-readable names or directory names, or the user’s default theme.
  • XdgIconTheme looks up icons by names such as document-new and returns the full path to the file. If used from GUI applications, it can also return a QPixmap, rescaled to the required size if there is no exact match.

Q-XDG library at Google Code

Comments

jopsen.dk posted at 2009-12-02 12:18:24

You might want to consider making it portable, e.g. to windows too… Perhaps by including tango icons…

I played with Qt on multiple platforms a while ago, and found myself using tango icons because that was the only icons on all platforms…

lucidfox.org posted at 2009-12-02 12:53:40

Perhaps the simplest way to implement cross-platform support would be to make the XdgIconManager constructor accept an optional parameter – a list of overrides for data directories? Then the Windows version of the application can simply bundle its themes in its installation, as long as the directories are in an XDG-compliant format.

launchpad.net/~flavio-tordini posted at 2009-12-02 14:36:11

Check this:
http://doc.trolltech.com/4.6/qicon.html#fromTheme

lucidfox.org posted at 2009-12-02 15:00:57

facepalm

I feel so stupid now.

vadi.myopenid.com posted at 2009-12-02 17:23:10

Don’t worry, they only released it yesterday. Took them a while to get it in.

Glad I found this though, will make use of this :)

lucidfox.org posted at 2009-12-02 17:54:14

Well, it’s still a bit ironic that I wrote a library for functionality that appeared in a release of Qt proper made that very day. :p

Although this library is more powerful than QIcon::fromTheme — unless Qt now has a way to enumerate themes too, or actually get the filename for the icon.

You must be logged in with OpenID to post comments.