PyQt6(没有pyrcc)如何提供资源? [英] How can resources be provided in PyQt6 (which has no pyrcc)?

查看:229
本文介绍了PyQt6(没有pyrcc)如何提供资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PyQt6 文档指出

移除了对 Qt 资源系统的支持(即没有 pyrcc6).

Support for Qt’s resource system has been removed (i.e. there is no pyrcc6).

有鉴于此,应该如何为 PyQt6 应用程序提供资源?

In light of this, how should one provide resources for a PyQt6 application?

推荐答案

已有一些讨论后在 PyQt 邮件列表上发现.

There has been some discussion on the PyQt mailing list when this was found out.

维护者不再对维护 pyrcc 感兴趣,因为他认为考虑到 python 已经使用了多个文件,他认为它不会提供任何主要好处.

The maintainer is not interested in maintaining pyrcc anymore as he believes that it doesn't provide any major benefit considering that python already uses multiple files anyway.

最简单的解决方案可能是使用QDir的静态方法setSearchPaths()addSearchPath().

The easiest solution is probably to use the static methods of QDir setSearchPaths() or addSearchPath().

不同之处在于资源将使用用于上述方法的前缀加载.

The difference will be that resources will be loaded using the prefix used for the methods above.

考虑到之前的情况:

icon = QtGui.QIcon(':/icons/myicon.png')

现在会变成这样:

# somewhere at the beginning of your program
QtCore.QDir.addSearchPath('icons', 'path_to_icons/')

icon = QtGui.QIcon('icons:myicon.png')

这篇关于PyQt6(没有pyrcc)如何提供资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆