qtawesome.icon

qtawesome.icon(*names, **kwargs)[source]

Return a QIcon object corresponding to the provided icon name(s).

This function is the main interface of qtawesome.

It can be used to create a QIcon instance from a single glyph or from a list of glyphs that are displayed on the top of each other. Such icon stacks are generally used to combine multiple glyphs to make more complex icons.

Glyph names are specified by strings, of the form prefix.name. The prefix corresponds to the font to be used and name is the name of the icon.

  • The prefix corresponding to Font-Awesome 4.x is ‘fa’

  • The prefix corresponding to Font-Awesome 5.x (regular) is ‘fa5’

  • The prefix corresponding to Font-Awesome 5.x (solid) is ‘fa5s’

  • The prefix corresponding to Font-Awesome 5.x (brands) is ‘fa5b’

  • The prefix corresponding to Elusive-Icons is ‘ei’

  • The prefix corresponding to Material-Design-Icons 5.x is ‘mdi’

  • The prefix corresponding to Material-Design-Icons 6.x is ‘mdi6’

  • The prefix corresponding to Phosphor is ‘ph’

  • The prefix corresponding to Remix-Icon is ‘ri’

  • The prefix corresponding to Microsoft’s Codicons is ‘msc’

When requesting a single glyph, options (such as color or positional offsets) can be passed as keyword arguments:

import qtawesome as qta

music_icon = qta.icon(
    'fa5s.music',
    color='blue',
    color_active='orange')

When requesting multiple glyphs, the options keyword argument contains the list of option dictionaries to be used for each glyph:

camera_ban = qta.icon('fa5s.camera', 'fa5s.ban', options=[{
        'scale_factor': 0.5,
        'active': 'fa5s.balance-scale'
    }, {
        'color': 'red',
        'opacity': 0.7
    }])

Qt’s QIcon object has four modes

  • Normal: The user is not interacting with the icon, but the functionality represented by the icon is available.

  • Disabled: The functionality corresponding to the icon is not available.

  • Active: The functionality corresponding to the icon is available. The user is interacting with the icon, for example, moving the mouse over it or clicking it.

  • Selected: The item represented by the icon is selected.

The glyph for the Normal mode is the one specified with the main positional argument.

  • color: icon color in the Normal mode.

The following four options will apply to the icon regardless of the mode.

  • offset: tuple (x, y) corresponding to the horizontal and vertical offsets for the glyph, specified as a proportion of the icon size.

  • animation: animation object for the icon.

  • scale_factor: multiplicative scale factor to be used for the glyph.

The following options apply to the different modes of the icon

  • active: name of the glyph to be used when the icon is Active.

  • color_active: the corresponding icon color.

  • disabled: name of the glyph to be used when the icon is Disabled.

  • color_disabled: the corresponding icon color.

  • selected: name of the glyph to be used when the icon is Selected.

  • color_selected: the corresponding icon color.

Default values for these options can be specified via the function set_defaults. If unspecified, the default defaults are:

{
    'opacity': 1.0,
    'scale_factor': 1.0
    'color': QColor(50, 50, 50),
    'color_disabled': QColor(150, 150, 150),
}

If no default value is provided for active, disabled or selected the glyph specified for the Normal mode will be used.