I have a custom add-on and I would like to create a dropdown list based on an EnumProperty, but I want the items in the list to take custom icons rather than the icons available within blender. I know that you can use import bpy.utils.previews to load custom icons into add-ons and set label's icon_value to custom icon ids, but I would like to be able to do the same with the items in a drop down list built based on an EnumProperty.
I have the following case for an add-on defining a class that will have a drop-down lists in which I want to have custom icons added to EACE item in the list. I want custom icons to show next to each item in the list as the drop down list is open (not just next to the closed drop down list: see image below):
# defined globally
easingItems = [
("EASE_IN", "Ease In", "", "", 0),
("EASE_OUT", "Ease Out", "", "", 1),
("EASE_IN_OUT", "Ease In-Out", "", "", 2)]
# prop defined in the addon/node class
easingType = EnumProperty(
name="Easing",
default="EASE_IN",
items=easingItems,
update=updateNode)
# then, in the draw UI
def draw_buttons(self, context, layout):
# this is when I want the enum property to be displayed with custom icons (how?)
layout.prop(self, ‘easingType', expand=False)
Left: This is a drop down list based on an enum property with some default blender icons. Right: This is a drop-down list based on a list needing custom icons (displayed as having default blender icons)
The result after Jerryno’s solution looks like this: