The documentation for PyQt6 states that
Support for Qt’s resource system has been removed (i.e. there is no
pyrcc6).
In light of this, how should one provide resources for a PyQt6 application?
There has been some discussion on the PyQt mailing list when this was found out.
The maintainer is not interested in maintaining pyrcc anymore as he believes that it doesn't provide any major benefit considering that python already uses multiple files anyway.
The easiest solution is probably to use the static methods of QDir setSearchPaths() or addSearchPath().
The difference will be that resources will be loaded using the prefix used for the methods above.
Considering the previous situation:
icon = QtGui.QIcon(':/icons/myicon.png')
Now it would become like this:
# somewhere at the beginning of your program
QtCore.QDir.addSearchPath('icons', 'path_to_icons/')
icon = QtGui.QIcon('icons:myicon.png')
The consensus seems to be that the existing python facilities should be used instead of pyrrc. So the resources would be stored directly in the file-system (perhaps within archive files), and then located using importlib.resources (python >= 3.7), or pkg_resources, or a third-party solution like importlib_resources. Exactly how this maps to existing uses of pyrcc will probably be application-specific, so some experimentation will be needed to find the best approach.
For more details on how to use these facilities, see:
As I started to use PyQt6, I found missing full support for Qt6 Resources. Especially when using designer and using images for buttons, labels etc. I tried addSearchPath, but still had to edit generated .py template. After some research I found using importlab the best solution for my problem.
I made simple script, which is using .qrc file and generates .py templates with importpath.
For example changing:
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/icons/icon1.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
to:
icon = QtGui.QIcon()
with path("myPackage.resources.icons", "icon1.png") as f_path:
icon.addPixmap(QtGui.QPixmap(str(f_path)), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
Here is a link to GitLab repo: https://github.com/domarm-comat/pyqt6rc
Or install via pip:
python3 -m pip install pyqt6rc