Colored icons in add-on

Hi devs!

There is now color coded icons in blender.
So, if you try to open a built in Icon Viewer add-on you will see this:

All nice icons with colors and without!
But, unfortunately, if try to run a simple script with icons (used one from template as an example), all icons just white:

%D0%B8%D0%B7%D0%BE%D0%B1%D1%80%D0%B0%D0%B6%D0%B5%D0%BD%D0%B8%D0%B5

import bpy


class HelloWorldPanel(bpy.types.Panel):
    """Creates a Panel in the Object properties window"""
    bl_label = "Hello World Panel"
    bl_idname = "OBJECT_PT_hello"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "object"

    def draw(self, context):
        layout = self.layout

        obj = context.object

        row = layout.row()
        row.label(text="Hello world!", icon='WORLD_DATA')

        row = layout.row()
        row.label(text="Active object is: " + obj.name)
        row = layout.row()
        row.prop(obj, "name")

        row = layout.row()
        row.operator("mesh.primitive_cube_add", icon='OUTLINER_OB_MESH')
        row.operator("mesh.primitive_cube_add", icon='MATERIAL')
        row.operator("mesh.primitive_cube_add", icon='MOD_UVPROJECT')
        row.operator("mesh.primitive_cube_add", icon='OUTLINER_DATA_LATTICE')


def register():
    bpy.utils.register_class(HelloWorldPanel)


def unregister():
    bpy.utils.unregister_class(HelloWorldPanel)


if __name__ == "__main__":
    register()

I tried to analyse Icons Viewer add-on, but it seems there is no any magic or special parameters behind it, just operators with icons as in my example. What am I doing wrong?

2 Likes

The theme will override colour in the icon. You have to make the theme icon colour saturation to literally black to see the icon colours.

I don’t get you. How theme icon colors related to icons referenced in script?

This happens because icon colors are taken from the theme, but only currently allowed to be shown in certain contexts, such as the Outliner.

This will probably become more generic, so we can use themable icon colors more places in the UI.

Now I understand - It is context and theme dependent, thanx for explanation!

What is an Icon Viewer addon?

Hi!

Icon Viewer addon is built in blender so you can easily search icons. You just need to enable it in preferences.

1 Like