PyQt和PySide应用程序中的FontAwesome图标
项目描述
QtAwesome
版权所有 © 2015- Spyder项目贡献者
描述
QtAwesome使Font Awesome和Elusive Icons等图标字体在PyQt和PySide应用程序中可用。
它最初是Rick Blommers的QtAwesome C++库(见QtAwesome)的Python端口。
安装
使用conda
conda install qtawesome
或使用pip
(如果您没有安装conda)
pip install qtawesome
用法
支持的字体
QtAwesome通过前缀和图标名称识别图标,名称之间用点(.
)分隔。
以下前缀目前可用
-
-
FA 5.15.4版本提供1,608个不同风格的免费图标
-
fa
是旧版本的FA 4.7版本,包含675个图标,但所有这些图标(以及更多!)都是FA 5.x版本的一部分,因此您可能需要使用上面的新版本。
-
-
ei
前缀包含Elusive Icons 2.0,包含304个图标。 -
msc
前缀包含微软的Codicons 0.0.35,包含540个图标。
示例
import qtawesome as qta
- 使用Font Awesome、Elusive Icons、Material Design Icons、Phosphor、Remix Icon或微软的Codicons。
# Get FontAwesome 5.x icons by name in various styles:
fa5_icon = qta.icon('fa5.flag')
fa5_button = QtWidgets.QPushButton(fa5_icon, 'Font Awesome! (regular)')
fa5s_icon = qta.icon('fa5s.flag')
fa5s_button = QtWidgets.QPushButton(fa5s_icon, 'Font Awesome! (solid)')
fa5b_icon = qta.icon('fa5b.github')
fa5b_button = QtWidgets.QPushButton(fa5b_icon, 'Font Awesome! (brands)')
# or Elusive Icons:
asl_icon = qta.icon('ei.asl')
elusive_button = QtWidgets.QPushButton(asl_icon, 'Elusive Icons!')
# or Material Design Icons:
apn_icon = qta.icon('mdi6.access-point-network')
mdi6_button = QtWidgets.QPushButton(apn_icon, 'Material Design Icons!')
# or Phosphor:
mic_icon = qta.icon('ph.microphone-fill')
ph_button = QtWidgets.QPushButton(mic_icon, 'Phosphor!')
# or Remix Icon:
truck_icon = qta.icon('ri.truck-fill')
ri_button = QtWidgets.QPushButton(truck_icon, 'Remix Icon!')
# or Microsoft's Codicons:
squirrel_icon = qta.icon('msc.squirrel')
msc_button = QtWidgets.QPushButton(squirrel_icon, 'Codicons!')
- 应用一些样式
# Styling icons
styling_icon = qta.icon('fa5s.music',
active='fa5s.balance-scale',
color='blue',
color_active='orange')
music_button = QtWidgets.QPushButton(styling_icon, 'Styling')
- 设置颜色中的透明度
# Setting an alpha of 120 to the color of this icon. Alpha must be a number
# between 0 and 255.
icon_with_alpha = qta.icon('mdi.heart',
color=('red', 120))
heart_button = QtWidgets.QPushButton(icon_with_alpha, 'Setting alpha')
- 堆叠多个图标
# Stacking icons
camera_ban = qta.icon('fa5s.camera', 'fa5s.ban',
options=[{'scale_factor': 0.5,
'active': 'fa5s.balance-scale'},
{'color': 'red'}])
stack_button = QtWidgets.QPushButton(camera_ban, 'Stack')
stack_button.setIconSize(QtCore.QSize(32, 32))
- 定义绘制图标的方式(
text
- 默认用于无动画的图标,path
- 默认用于有动画的图标,glyphrun
和image
)
# Icon drawn with the `image` option
drawn_image_icon = qta.icon('ri.truck-fill',
options=[{'draw': 'image'}])
drawn_image_button = QtWidgets.QPushButton(drawn_image_icon,
'Icon drawn as an image')
- 动画
# Spining icons
spin_button = QtWidgets.QPushButton(' Spinning icon')
animation = qta.Spin(spin_button)
spin_icon = qta.icon('fa5s.spinner', color='red', animation=animation)
spin_button.setIcon(spin_icon)
# Stop the animation when needed
animation.stop()
- 将图标显示为小部件
# Spining icon widget
spin_widget = qta.IconWidget()
animation = qta.Spin(spin_widget, autostart=False)
spin_icon = qta.icon('mdi.loading', color='red', animation=animation)
spin_widget.setIcon(spin_icon)
# Simple icon widget
simple_widget = qta.IconWidget('mdi.web', color='blue',
size=QtCore.QSize(16, 16))
# Start and stop the animation when needed
animation.start()
animation.stop()
- 截图
要检查这些选项,您可以启动example.py
脚本并将选项作为参数传递。例如,要测试使用glyphrun
绘制选项时图标的外观,您可以运行类似以下命令:
python example.py draw=glyphrun
其他功能
- QtAwesome捆绑了Font Awesome、Elusive Icons、Material Design Icons、Phosphor、Remix Icon和微软的Codicons,但它也可以与其他图标字体一起使用。`load_font`函数允许动态加载其他字体。
- QtAwesome依赖于QtPy项目作为PyQt或PySide的兼容层。
图标浏览器
QtAwesome附带了一个浏览器,显示所有可用图标。您可以使用它来查找符合您要求的图标,然后复制创建该图标时应使用的名称!
安装后,从shell中运行qta-browser
以启动浏览器。
许可协议
MIT许可。版权所有 2015 - Spyder开发团队。有关详细信息,请参阅LICENSE文件。
Font Awesome和Elusive Icons字体根据SIL开源字体许可证许可。
Phosphor字体根据MIT许可证许可。
Material Design Icons字体根据Apache许可证版本2.0许可。
Remix Icon 字体许可协议遵循 Apache License Version 2.0。
微软的 Codicons 许可协议遵循 Creative Commons Attribution 4.0 International Public License。
赞助商
Spyder 及其子项目得到以下机构的慷慨资助
以及我们从全球用户通过 Open Collective 收到的捐款
项目详情
下载文件
下载您平台上的文件。如果您不确定选择哪一个,请了解更多关于 安装包 的信息。
源分发
构建分发
QtAwesome-1.3.1.tar.gz 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 075b2c9ee01cbaf5e3a4bebed0e5529ee8605981355f21dea051b15c1b869e1b |
|
MD5 | 078a930c86cca0a2cd48df3135fe6854 |
|
BLAKE2b-256 | a4be3fa8df267d0651597acdefe124cd1595d3839aed3ce97da902efc44a2160 |
QtAwesome-1.3.1-py3-none-any.whl 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 6078449035cd5311bc461e99940a426c27cb919fb4211c8cfc64506cb71e2dd7 |
|
MD5 | 480c016bf9438c2e239658cb7276ed05 |
|
BLAKE2b-256 | 35b0f5d87ddd388917965377c64ae8ee70f3fa6cb565823be78f5c4bd0383ec5 |