Skip to content

Commit

Permalink
ENH: Re-introduce Qt resource support in Python
Browse files Browse the repository at this point in the history
This commit re-introduces the support removed in c91fa78 (COMP: Remove
unused python-based Qt resource file).

It also ensures that the resources are available through Qt resource
system by importing the corresponding module.

This is particularly relevant when styling application through qss stylesheet
where icons can be referenced setting attribute like  the following:

  image: url(":/Icons/Image.svg");

The "Gears.png" icon is added only for the sake of testing the generation of
the python-based Qt resource file and may be removed after populating the
file.
  • Loading branch information
jcfr committed Feb 2, 2023
1 parent f373eef commit 05e8429
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@ set(MODULE_PYTHON_RESOURCES
Resources/Home.qss
)

slicerFunctionAddPythonQtResources(MODULE_PYTHON_QRC_RESOURCES
Resources/${MODULE_NAME}.qrc
)

#-----------------------------------------------------------------------------
slicerMacroBuildScriptedModule(
NAME ${MODULE_NAME}
SCRIPTS ${MODULE_PYTHON_SCRIPTS}
SCRIPTS ${MODULE_PYTHON_SCRIPTS} ${MODULE_PYTHON_QRC_RESOURCES}
RESOURCES ${MODULE_PYTHON_RESOURCES}
)

3 changes: 3 additions & 0 deletions {{cookiecutter.project_name}}/Modules/Scripted/Home/Home.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

import SlicerCustomAppUtilities

# Import to ensure the files are available through the Qt resource system
from Resources import HomeResources


class Home(ScriptedLoadableModule):
"""The home module allows to orchestrate and style the overall application workflow.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE RCC>
<!--
This file was automatically generated by genqrc.py ['./Icons/']
See http://www.slicer.org/slicerWiki/index.php/Documentation/Nightly/Developers/Build_system/Qt_resource_files for more information.
-->

<RCC version="1.0">

<qresource prefix="Icons">
<file alias="Gears.png">./Icons/Gears.png</file>
</qresource>

</RCC>

0 comments on commit 05e8429

Please sign in to comment.