跳转到主要内容

PyQt和PySide应用程序中的FontAwesome图标

项目描述

QtAwesome

license pypi version conda version download count OpenCollective Backers Join the chat at https://gitter.im/spyder-ide/public
PyPI status Github Windows build status Github Linux build status Github MacOS build status Documentation Status codecov

版权所有 © 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通过前缀和图标名称识别图标,名称之间用点(.)分隔。

以下前缀目前可用

示例

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 - 默认用于有动画的图标,glyphrunimage
# 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()
  • 截图

QtAwesome screenshot

要检查这些选项,您可以启动example.py脚本并将选项作为参数传递。例如,要测试使用glyphrun绘制选项时图标的外观,您可以运行类似以下命令:

python example.py draw=glyphrun

其他功能

  • QtAwesome捆绑了Font AwesomeElusive IconsMaterial Design IconsPhosphorRemix Icon和微软的Codicons,但它也可以与其他图标字体一起使用。`load_font`函数允许动态加载其他字体。
  • QtAwesome依赖于QtPy项目作为PyQt或PySide的兼容层。

图标浏览器

QtAwesome附带了一个浏览器,显示所有可用图标。您可以使用它来查找符合您要求的图标,然后复制创建该图标时应使用的名称!

安装后,从shell中运行qta-browser以启动浏览器。

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 及其子项目得到以下机构的慷慨资助

QuansightNumfocus

以及我们从全球用户通过 Open Collective 收到的捐款

Sponsors

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪一个,请了解更多关于 安装包 的信息。

源分发

QtAwesome-1.3.1.tar.gz (2.4 MB 查看哈希)

上传时间 源代码

构建分发

QtAwesome-1.3.1-py3-none-any.whl (2.4 MB 查看哈希)

上传时间 Python 3

由以下赞助商支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面