How to reference resource file in PyQt stylesheet using fbs

爷,独闯天下 提交于 2021-02-10 19:34:13

问题


I am building a PyQt5 application using fbs and (following this tutorial) have placed the image files in the directory /src/main/resources/base/images. This way the image resources are available to the Python code using ApplicationContext.get_resource("images/xxxx.png"). The build system manages the correct file path depending on whether we are running from source or the compiled version of the app.

I would like to access these images in my PyQt stylesheets, along the lines of

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

however, the above code doesn't display the image.

Is there a way to reference fbs resources from within PyQt5 stylesheets?


回答1:


When you use ":" it is assumed that you are using a qresource but fbs does not use it, so you must use the local path:

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/how-to-reference-resource-file-in-pyqt-stylesheet-using-fbs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!