| 1 |
Usage |
| 2 |
----- |
| 3 |
|
| 4 |
Supported Fonts |
| 5 |
~~~~~~~~~~~~~~~ |
| 6 |
|
| 7 |
QtAwesome identifies icons by their **prefix** and their **icon name**, separated by a *period* (``.``) character. |
| 8 |
|
| 9 |
The following prefixes are currently available to use: |
| 10 |
|
| 11 |
- `FontAwesome`_: |
| 12 |
|
| 13 |
- FA 6.7.2 features 2,060 free icons in different styles: |
| 14 |
|
| 15 |
- ``fa6`` prefix has `163 icons in the "regular" style.`_ |
| 16 |
- ``fa6s`` prefix has `1402 icons in the "solid" style.`_ |
| 17 |
- ``fa6b`` prefix has `495 icons of various brands.`_ |
| 18 |
|
| 19 |
- FA 5.15.4 features 1,608 free icons in different styles: |
| 20 |
|
| 21 |
- ``fa5`` prefix has `151 icons in the "regular" style.`_ |
| 22 |
- ``fa5s`` prefix has `1001 icons in the "solid" style.`_ |
| 23 |
- ``fa5b`` prefix has `456 icons of various brands.`_ |
| 24 |
|
| 25 |
- ``ei`` prefix holds `Elusive Icons 2.0 with its 304 icons`_. |
| 26 |
|
| 27 |
- `Material Design Icons`_: |
| 28 |
|
| 29 |
- ``mdi6`` prefix holds `Material Design Icons 6.9.96 with its 6997 icons.`_ |
| 30 |
|
| 31 |
- ``mdi`` prefix holds `Material Design Icons 5.9.55 with its 5955 icons.`_ |
| 32 |
|
| 33 |
- ``ph`` prefix holds `Phosphor 1.3.0 with its 4470 icons (894 icons * 5 weights: Thin, Light, Regular, Bold and Fill).`_ |
| 34 |
|
| 35 |
- ``ri`` prefix holds `Remix Icon 2.5.0 with its 2271 icons.`_ |
| 36 |
|
| 37 |
- ``msc`` prefix holds Microsoft's `Codicons 0.0.36 with its 569 icons.`_ |
| 38 |
|
| 39 |
.. _FontAwesome: https://fontawesome.com |
| 40 |
.. _163 icons in the "regular" style.: https://fontawesome.com/v6/search?o=r&ic=free&s=regular |
| 41 |
.. _1402 icons in the "solid" style.: https://fontawesome.com/v6/search?o=r&ic=free&s=solid |
| 42 |
.. _495 icons of various brands.: https://fontawesome.com/v6/search?o=r&ic=free&ip=brands |
| 43 |
.. _151 icons in the "regular" style.: https://fontawesome.com/v5/search?o=r&ic=free&s=regular |
| 44 |
.. _1001 icons in the "solid" style.: https://fontawesome.com/v5/search?o=r&ic=free&s=solid |
| 45 |
.. _456 icons of various brands.: https://fontawesome.com/v5/search?ic=brands |
| 46 |
.. _Elusive Icons 2.0 with its 304 icons: http://elusiveicons.com/icons/ |
| 47 |
.. _Material Design Icons: https://pictogrammers.com/library/mdi/ |
| 48 |
.. _Material Design Icons 6.9.96 with its 6997 icons.: https://cdn.materialdesignicons.com/6.9.96/ |
| 49 |
.. _Material Design Icons 5.9.55 with its 5955 icons.: https://cdn.materialdesignicons.com/5.9.55/ |
| 50 |
.. _Phosphor 1.3.0 with its 4470 icons (894 icons * 5 weights\: Thin, Light, Regular, Bold and Fill).: https://github.com/phosphor-icons/phosphor-icons |
| 51 |
.. _Remix Icon 2.5.0 with its 2271 icons.: https://github.com/Remix-Design/RemixIcon |
| 52 |
.. _Codicons 0.0.36 with its 569 icons.: https://github.com/microsoft/vscode-codicons |
| 53 |
|
| 54 |
Examples |
| 55 |
~~~~~~~~ |
| 56 |
|
| 57 |
.. code:: python |
| 58 |
|
| 59 |
import qtawesome as qta |
| 60 |
|
| 61 |
- Use Font Awesome, Elusive Icons, Material Design Icons, Phosphor, Remix Icon or Microsoft's Codicons: |
| 62 |
|
| 63 |
.. code:: python |
| 64 |
|
| 65 |
# Get FontAwesome 6.x icons by name in various styles: |
| 66 |
fa6_icon = qta.icon('fa6.flag') |
| 67 |
fa6_button = QtWidgets.QPushButton(fa6_icon, 'Font Awesome 6! (regular)') |
| 68 |
|
| 69 |
fa6s_icon = qta.icon('fa6s.flag') |
| 70 |
fa6s_button = QtWidgets.QPushButton(fa6s_icon, 'Font Awesome 6! (solid)') |
| 71 |
|
| 72 |
fa6b_icon = qta.icon('fa6b.github') |
| 73 |
fa6b_button = QtWidgets.QPushButton(fa6b_icon, 'Font Awesome 6! (brands)') |
| 74 |
|
| 75 |
# Get FontAwesome 5.x icons by name in various styles: |
| 76 |
fa5_icon = qta.icon('fa5.flag') |
| 77 |
fa5_button = QtWidgets.QPushButton(fa5_icon, 'Font Awesome 5! (regular)') |
| 78 |
|
| 79 |
fa5s_icon = qta.icon('fa5s.flag') |
| 80 |
fa5s_button = QtWidgets.QPushButton(fa5s_icon, 'Font Awesome 5! (solid)') |
| 81 |
|
| 82 |
fa5b_icon = qta.icon('fa5b.github') |
| 83 |
fa5b_button = QtWidgets.QPushButton(fa5b_icon, 'Font Awesome 5! (brands)') |
| 84 |
|
| 85 |
# Get Elusive icons by name |
| 86 |
asl_icon = qta.icon('ei.asl') |
| 87 |
elusive_button = QtWidgets.QPushButton(asl_icon, 'Elusive Icons!') |
| 88 |
|
| 89 |
# Get Material Design icons 6.x by name |
| 90 |
apn_icon = qta.icon('mdi6.access-point-network') |
| 91 |
mdi6_button = QtWidgets.QPushButton(apn_icon, 'Material Design Icons!') |
| 92 |
|
| 93 |
# Get Phosphor by name |
| 94 |
mic_icon = qta.icon('ph.microphone-fill') |
| 95 |
ph_button = QtWidgets.QPushButton(mic_icon, 'Phosphor!') |
| 96 |
|
| 97 |
# Get Remix Icon by name |
| 98 |
truck_icon = qta.icon('ri.truck-fill') |
| 99 |
ri_button = QtWidgets.QPushButton(truck_icon, 'Remix Icon!') |
| 100 |
|
| 101 |
# Get Microsoft's Codicons by name |
| 102 |
squirrel_icon = qta.icon('msc.squirrel') |
| 103 |
msc_button = QtWidgets.QPushButton(squirrel_icon, 'Codicons!') |
| 104 |
|
| 105 |
- Apply some transformations: |
| 106 |
|
| 107 |
.. code:: python |
| 108 |
|
| 109 |
# Rotated |
| 110 |
rot_icon = qta.icon('mdi.access-point-network', rotated=45) |
| 111 |
rot_button = QtWidgets.QPushButton(rot_icon, 'Rotated Icons!') |
| 112 |
|
| 113 |
# Horizontal flip |
| 114 |
hflip_icon = qta.icon('mdi.account-alert', hflip=True) |
| 115 |
hflip_button = QtWidgets.QPushButton(hflip_icon, 'Horizontally Flipped Icons!') |
| 116 |
|
| 117 |
# Vertical flip |
| 118 |
vflip_icon = qta.icon('mdi.account-alert', vflip=True) |
| 119 |
vflip_button = QtWidgets.QPushButton(vflip_icon, 'Vertically Flipped Icons!') |
| 120 |
|
| 121 |
- Apply some styling: |
| 122 |
|
| 123 |
.. code:: python |
| 124 |
|
| 125 |
# Styling |
| 126 |
styling_icon = qta.icon('fa5s.music', |
| 127 |
active='fa5s.balance-scale', |
| 128 |
color='blue', |
| 129 |
color_active='orange') |
| 130 |
music_button = QtWidgets.QPushButton(styling_icon, 'Styling') |
| 131 |
|
| 132 |
- Set alpha in colors: |
| 133 |
|
| 134 |
.. code:: python |
| 135 |
|
| 136 |
# Setting an alpha of 120 to the color of this icon. Alpha must be a number |
| 137 |
# between 0 and 255. |
| 138 |
icon_with_alpha = qta.icon('mdi.heart', |
| 139 |
color=('red', 120)) |
| 140 |
heart_button = QtWidgets.QPushButton(icon_with_alpha, 'Setting alpha') |
| 141 |
|
| 142 |
- Apply toggling state styling: |
| 143 |
|
| 144 |
.. code:: python |
| 145 |
|
| 146 |
# Toggle |
| 147 |
toggle_icon = qta.icon('fa5s.home', selected='fa5s.balance-scale', |
| 148 |
color_off='black', |
| 149 |
color_off_active='blue', |
| 150 |
color_on='orange', |
| 151 |
color_on_active='yellow') |
| 152 |
toggle_button = QtWidgets.QPushButton(toggle_icon, 'Toggle') |
| 153 |
toggle_button.setCheckable(True) |
| 154 |
|
| 155 |
- Define the way to draw icons (`text`- default for icons without animation, `path` - default for icons with animations, `glyphrun` and `image`): |
| 156 |
|
| 157 |
.. code:: python |
| 158 |
|
| 159 |
# Icon drawn with the `image` option |
| 160 |
drawn_image_icon = qta.icon('ri.truck-fill', |
| 161 |
options=[{'draw': 'image'}]) |
| 162 |
drawn_image_button = QtWidgets.QPushButton(drawn_image_icon, |
| 163 |
'Icon drawn as an image') |
| 164 |
|
| 165 |
- Stack multiple icons: |
| 166 |
|
| 167 |
.. code:: python |
| 168 |
|
| 169 |
# Stack icons |
| 170 |
camera_ban = qta.icon('fa5s.camera', 'fa5s.ban', |
| 171 |
options=[{'scale_factor': 0.5, |
| 172 |
'active': 'fa5s.balance-scale'}, |
| 173 |
{'color': 'red', 'opacity': 0.7}]) |
| 174 |
stack_button = QtWidgets.QPushButton(camera_ban, 'Stack') |
| 175 |
stack_button.setIconSize(QtCore.QSize(32, 32)) |
| 176 |
|
| 177 |
# Stack and offset icons |
| 178 |
saveall = qta.icon('fa5.save', 'fa5.save', |
| 179 |
options=[{'scale_factor': 0.8, |
| 180 |
'offset': (0.2, 0.2), |
| 181 |
'color': 'gray'}, |
| 182 |
{'scale_factor': 0.8}]) |
| 183 |
saveall_button = QtWidgets.QPushButton(saveall, 'Stack, offset') |
| 184 |
|
| 185 |
- Animations: |
| 186 |
|
| 187 |
.. code:: python |
| 188 |
|
| 189 |
# -- Spin icons |
| 190 |
spin_button = QtWidgets.QPushButton(' Spinning icon') |
| 191 |
animation = qta.Spin(spin_button) |
| 192 |
spin_icon = qta.icon('fa5s.spinner', color='red', animation=animation) |
| 193 |
spin_button.setIcon(spin_icon) |
| 194 |
|
| 195 |
# Stop animation when needed |
| 196 |
animation.stop() |
| 197 |
|
| 198 |
# -- Pulse icons |
| 199 |
pulse_button = QtWidgets.QPushButton(' Pulsing icon') |
| 200 |
animation = qta.Pulse(pulse_button, autostart=False) |
| 201 |
pulse_icon = qta.icon('fa5s.spinner', color='green', animation=animation) |
| 202 |
pulse_button.setIcon(pulse_icon) |
| 203 |
|
| 204 |
# Start and stop the animation when needed |
| 205 |
animation.start() |
| 206 |
animation.stop() |
| 207 |
|
| 208 |
# -- Stacked spin icons |
| 209 |
stack_spin_button = QtWidgets.QPushButton('Stack spin') |
| 210 |
animation = qta.Spin(stack_spin_button) |
| 211 |
options = [{'scale_factor': 0.4, |
| 212 |
'animation': animation}, |
| 213 |
{'color': 'blue'}] |
| 214 |
stack_spin_icon = qta.icon('ei.asl', 'fa5.square', |
| 215 |
options=options) |
| 216 |
stack_spin_button.setIcon(stack_spin_icon) |
| 217 |
stack_spin_button.setIconSize(QtCore.QSize(32, 32)) |
| 218 |
|
| 219 |
# Stop animation when needed |
| 220 |
animation.stop() |
| 221 |
|
| 222 |
- Apply font label rendering: |
| 223 |
|
| 224 |
.. code:: python |
| 225 |
|
| 226 |
# Render a label with this font |
| 227 |
label = QtWidgets.QLabel(unichr(0xf19c) + ' ' + 'Label') |
| 228 |
label.setFont(qta.font('fa', 16)) |
| 229 |
|
| 230 |
- Display Icon as a widget: |
| 231 |
|
| 232 |
.. code:: python |
| 233 |
|
| 234 |
# -- Spinning icon widget |
| 235 |
spin_widget = qta.IconWidget() |
| 236 |
animation = qta.Spin(spin_widget) |
| 237 |
spin_icon = qta.icon('mdi.loading', color='red', animation=animation) |
| 238 |
spin_widget.setIcon(spin_icon) |
| 239 |
|
| 240 |
# Stop animation when needed |
| 241 |
animation.stop() |
| 242 |
|
| 243 |
# -- Simple widget |
| 244 |
simple_widget = qta.IconWidget('mdi.web', color='blue', |
| 245 |
size=QtCore.QSize(16, 16)) |
| 246 |
|
| 247 |
Screenshot |
| 248 |
~~~~~~~~~~ |
| 249 |
|
| 250 |
.. image:: ../../qtawesome-screenshot.gif |