Senior Technical Artist

Personal Blog

Personal Blog

PySide - List Embedded Icons

First thing that I want to write is about how to list embedded icons (or files) in Qt applications.
In this example, I will be using PySide and The Foundry's Hiero (however, this technique can be applied to any Qt application).

Background

In one of my projects, I needed to create a selection that looks like this:

hiero_embedded_icons.jpg

As you can see, the highlighted icons are built-in Hiero icons. But how do we repurpose built-in icons like these?

Solution

Going through the example codes in Hiero's Python Dev Guide, I found that you can use the following code to use the built-in Video and Audio Track icons:

        def getIconForTrack(self,track):
            trackIcon = None
            if isinstance(track,hiero.core.AudioTrack):
                trackIcon = QIcon("icons:AudioOnly.png")
            elif isinstance(track,hiero.core.VideoTrack):
                trackIcon = QIcon("icons:VideoOnly.png")
            return trackIcon

If we have something like this, it is very simple to find the rest of the embedded icons.
This is how:

        import os
        from PySide import QtCore

        file = QtCore.QFile("icons:AudioOnly.png")
        directory = QtCore.QDir(os.path.dirname(file))
        print(directory.entryList())

Now, while the above solution will only work if we already know one of the embedded files; if you don't know a single embedded file in the Qt application you're working on, worry not. We can utilize the top directory and go down from there. 

And in case of Autodesk's Maya, most of the icons are already there!

        from PySide import QtCore
        directory = QtCore.QDir(":")
        print(directory.entryList())

That's it! Simple.