gpt4 book ai didi

python - 如何使用 fbs 在 PyQt 样式表中引用资源文件

转载 作者:行者123 更新时间:2023-12-01 07:56:48 25 4
gpt4 key购买 nike

我正在使用 fbs 构建 PyQt5 应用程序,并且 ( following this tutorial ) 已将图像文件放置在目录 /src/main/resources/base/images 中。这样,Python 代码就可以使用 ApplicationContext.get_resource("images/xxxx.png") 来使用图像资源。构建系统根据我们是从源代码运行还是从应用程序的编译版本运行来管理正确的文件路径。

我想在我的 PyQt 样式表中访问这些图像,沿着

QTreeView::branch:closed:has-children:has-siblings {
border-image: none;
image: url(:/images/branch-closed.png);

但是,上面的代码没有显示图像。

有没有办法从 PyQt5 样式表中引用 fbs 资源?

最佳答案

当您使用“:”时,假设您正在使用qresource,但fbs不使用它,因此您必须使用本地路径:

QSS = '''
QTreeView::branch:closed:has-children:has-siblings{
border-image: none;
image: url(%(branch_icon)s);
}
'''

# ...
appctxt = ApplicationContext()
branch_icon = appctxt.get_resource("images/branch-closed.png")
qss = QSS % {"branch_icon": branch_icon}
appctxt.app.setStyleSheet(qss)

关于python - 如何使用 fbs 在 PyQt 样式表中引用资源文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55930797/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com