Closed akshaybabloo closed 3 years ago
This is what I am doing so far to generate a qrc file:
import os
from pathlib import Path
from jinja2 import Environment, FileSystemLoader, select_autoescape
from qt_material import export_theme
root_path = os.path.abspath('../')
theme_path = os.path.join(root_path, "theme")
qss_path = os.path.join(root_path, "style.qss")
qrc_path = os.path.join(root_path, "style.qrc")
export_theme(theme='dark_teal.xml', qss=qss_path, output=theme_path, prefix=':theme/')
p = Path(theme_path)
files = ['/'.join(a.parts[-3:]) for a in p.glob("**/*.svg")]
env = Environment(loader=FileSystemLoader("."), autoescape=select_autoescape(['html', 'xml']))
template = env.get_template("styles.qrc")
render = template.render(files=files)
with open(qrc_path, 'w') as f:
f.write(render)
styles.qrc
<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
{%- for file in files %}
<file>{{ file }}</file>{% endfor %}
</qresource>
<qresource>
<file>style.qss</file>
</qresource>
</RCC>
Hi @akshaybabloo
There is no reason to use Qt resource system
, since you can handle any resource with Python techniques, even the pyrcc
tool will be deprecated in PyQt6.
Embed random files into a single Python file is not the proper way to handle resources, both Python and all operating systems has package manager that handle them without problems.
I honestly don't recommend using qrc
for new developments.
I am not too sure if that can be done in C++ though?
Qt resource system
is all fine and well for C++ programs where qresources
get statically linked into the executable itself, reducing the number of files to be installed.
I could get back the qrc
generation.
I am not too sure how the answer in #25 is being used. Because as far as I know qrc files are embedded into the static file.
Also, mac being mac, wants to know the path where it could find the icons from. I don't see any other way. Unless I am wrong.
Hi @akshaybabloo
I just add the rcc
argument to the export_theme
function.
export_theme(theme='dark_teal.xml', qss='dark_teal.qss', rcc='resources.rcc',
output='theme', prefix='icon:/', invert_secondary=False, extra=extra)
The .qss
will use the file:/
prefix by default .
Awesome! Thanks.
Thank you for adding the generate function in #25
Could you add a way to generate qrc file too? - https://doc.qt.io/qt-6/resources.html