Package: iconify
IconifyIconify allows you to createQIcons andQPixmaps from svg files with
different color and animation.  It provides a way of fetching popular image
packs such as Font Awesome, Material Design etc and installing them on the
path that's used for finding images.QuickstartTo get started with iconify, use the following commands:# Install iconifypipinstalliconify# Fetch the icon libraries - Font Awesome, Material Design etc.iconify-fetch# Start the icon browser to find the icon you wanticonify-browserOnce you have the icon browser open, search for the type of icon you want and
copy the name to the clipboard. Then you can jump into python:importiconifyasicoicon=ico.Icon('google-emojis:face-with-symbols-on-mouth')myQtButton.setIcon(icon)ConfigurationIconify will search paths identified by theICONIFY_PATHenvironment variable.
You can also set this at runtime with the following code:importiconifyasicoico.path.addIconDirectory('/path/to/icon/dir')You will also require a Qt python binding such asPySide2. Iconify will use the
binding identified by theICONIFY_QTLIBenvironment variable.  Set this variable
to the name required to import the python binding e.g.PySide2orPyQt5.
Iconify expects Qt5 interfaces so if you'd like to use this library with Qt4
you should consider using a shim such asQt.pyorQtPy.ExamplesSimpleThe following code will find the first occurrence of adelete.svgfile on theICONIFY_PATHenvironment variable and use it as is.importiconifyasicoicon=ico.Icon('delete')button.setIcon(icon)Changing ColorTo set the color of the icon, provide aQColorobject via thecolorkwarg:importiconifyasicofromiconify.qtimportQtGui,QtWidgetsicon=ico.Icon('filters',color=QtGui.QColor('salmon'))button=QtWidgets.QPushButton()button.setIcon(icon)AnimationFor animation, instantiate an animation object and pass it in via theanimkwarg:importiconifyasicofromiconify.qtimportQtGui,QtWidgetsanim=ico.anim.Spin()icon=ico.Icon(# The ':' here denotes a directory and provides cross platform support.'spinners:simple',color=QtGui.QColor('lightblue'),anim=anim,)# `icon.setAsButtonIcon` is used here so that the animation# used by the icon will update the widget when it plays.button=QtWidgets.QPushButton()icon.setAsButtonIcon(button)# Start the animationanim.start()Multi State IconsTo create a multi state icon, calladdStatewith the appropriatemodeandstatekwargs to set the values you want.importiconifyasicofromiconify.qtimportQtGui,QtWidgetsonHoverAnimation=ico.anim.Spin()icon=ico.Icon('filters',color=QtGui.QColor('salmon'))# When the button has focus, make it green and spinning.icon.addState('filters',color=QtGui.QColor('seagreen'),anim=onHoverAnimation,mode=QtGui.QIcon.Active,)# Make it gray when it's disabled.icon.addState('filters',color=QtGui.QColor('gray'),mode=QtGui.QIcon.Disabled,)button=QtWidgets.QPushButton()button.setIcon(icon)# Connect directly to the animation here to# ensure that the button animates on hover.onHoverAnimation.tick.connect(button.update)Advanced AnimationThe same animation object can be used with multiple icons, and the same icon can be applied
to multiple buttons.  This is useful when you want numerous widgets to update when
an event happens e.g. loading something:importiconifyasicofromiconify.qtimportQtGui,QtWidgets# Animations can be added together using the + operator.loadingAnim=ico.anim.Spin()+ico.anim.Breathe()# Instantiate two icons with the same animationsimpleIcon=ico.Icon('spinners:simple',color=QtGui.QColor('lightblue'),anim=loadingAnim,)detailedIcon=ico.Icon('spinners:detailed',color=QtGui.QColor('grey'),anim=loadingAnim,)# Use those icons on multiple buttonssmallButtonOne=QtWidgets.QPushButton()simpleIcon.setAsButtonIcon(smallButtonOne)smallButtonTwo=QtWidgets.QPushButton()simpleIcon.setAsButtonIcon(smallButtonTwo)largeButtonOne=QtWidgets.QPushButton()detailedIcon.setAsButtonIcon(largeButtonOne)largeButtonTwo=QtWidgets.QPushButton()detailedIcon.setAsButtonIcon(largeButtonTwo)defloadData():# Start the animation.  All buttons using the two icons# from above should start to animate.loadingAnim.start()# Do a long running process here, preferably in a separate# thread to keep the user interface refreshing nicely.# Stop the animation now that the work has been done.loadingAnim.stop()PixmapsIt's also possible to use iconify to create pixmaps.  The following code is a
customQLabelsubclass which using iconify to draw aQPixmapin the center of
the label:importiconifyasicofromiconify.qtimportQtCore,QtGui,QtWidgetsclassIconifyLabel(QtWidgets.QLabel):def__init__(self,pixmapGenerator):super(IconifyLabel,self).__init__()self._pixmapGenerator=pixmapGenerator# Ensure this label updates when the animation ticks.self._pixmapGenerator.anim().tick.connect(self.update)defpaintEvent(self,event):super(IconifyLabel,self).paintEvent(event)rect=event.rect()ifrect.width()>rect.height():size=QtCore.QSize(rect.height(),rect.height())else:size=QtCore.QSize(rect.width(),rect.width())pixmap=self._pixmapGenerator.pixmap(size)painter=QtGui.QPainter(self)halfSize=size/2point=rect.center()-QtCore.QPoint(halfSize.width(),halfSize.height())painter.drawPixmap(point,pixmap)painter.end()anim=ico.anim.Spin()pixmapGenerator=ico.PixmapGenerator('loading',color=QtGui.QColor('orange'),anim=anim,)label=IconifyLabel(pixmapGenerator)anim.start()