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

时间:2019-05-01 02:02:08

标签: python pyqt5 fbs

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

我想按照

的方式在PyQt样式表中访问这些图像。
QTreeView::branch:closed:has-children:has-siblings {
    border-image: none;
    image: url(:/images/branch-closed.png);

但是,上面的代码不会显示图像。

是否可以在PyQt5样式表中引用fbs资源?

1 个答案:

答案 0 :(得分:1)

使用“:”时,假设您使用的是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)