Icon themes for pure Qt applications
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:
XdgIconManagerkeeps the list of themes installed in the system, and returns themes by human-readable names or directory names, or the user’s default theme.XdgIconThemelooks up icons by names such asdocument-newand returns the full path to the file. If used from GUI applications, it can also return aQPixmap, rescaled to the required size if there is no exact match.
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…
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.
Check this:
http://doc.trolltech.com/4.6/qicon.html#fromTheme
facepalm
I feel so stupid now.
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 :)
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.