# How to add custom icon to actions via python scripting?

**URL:** <https://krita-artists.org/t/how-to-add-custom-icon-to-actions-via-python-scripting/62752>\
**Category:** Developer Questions\
**Tags:** scripting-help\
**Created:** [April 12, 2023, 10:33pm UTC](https://krita-artists.org/t/how-to-add-custom-icon-to-actions-via-python-scripting/62752 "2023-04-12T22:33:25Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![kaichi1342](https://krita-artists.org/user_avatar/krita-artists.org/kaichi1342/32/8174_2.png) [@kaichi1342](https://krita-artists.org/u/kaichi1342)\
**Post date:** [April 24, 2023, 1:30pm UTC](https://krita-artists.org/t/how-to-add-custom-icon-to-actions-via-python-scripting/62752/15 "2023-04-24T13:30:00Z")

</div>

some tips:  
plugin developer plugin is good for hunting down names for krita i con set.  
QToolbutton QPushButton have setIcon method.

nameofbutton.setIcon(icon)

icon is an object of type QIcon i think… so you can get one of the set krita icon by

Krita.instance().icon(‘name of krita icon’)  
ie . Krita.instance().icon(‘view-list-text’)

so something like  
nameofbutton.setIcon( Krita.instance().icon(‘view-list-text’) )

refer to @KnowZero example.

Now for custom icons - thats a bit more work. I only have experience in making sets from svg.  
for that I followed Krita style of svg as much as possible.

Which is create 22x22 px svg icon set and save them in a folder inside your plugin. [one for light background one for dark]

Also you need to create a custom class, to pick up the image, this include a dictionary of name a method that will make the svg become QIcon. It helps if you pattern it to krita with the _icon_ method returning an icon object.

converting an svg to QIcon:  
QIcon icon1 = QIcon()  
icon1.addFile(path\_to\_icon\_file, size\_of\_icon)

if you are interested with custom icons, I can offer my plugin [CompactBrushToggler](https://krita-artists.org/t/compact-brush-toggler/33798/72) as reference. I have a class name CBT\_Icon that can be use to pattern your code.

---

_[View the full topic](https://krita-artists.org/t/how-to-add-custom-icon-to-actions-via-python-scripting/62752)._
