我正在使用fbs构建一个PyQt5应用程序,并且(遵循本教程)已经将图像文件放置在/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资源?
发布于 2019-05-01 02:29:57
当您使用":“时,假设您使用的是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)https://stackoverflow.com/questions/55930797
复制相似问题