The tool offers no help whatsoever what the argument does and a colleague of mine is facing the issue of having to add the Python module generated by processing a QRC file (pyside2-rcc
) to the Python module generated by processing the UI file (pyside2-uic
) that includes items from the QRC file.
In C++ with CMake I don't have such an issue so I'm confused as to what needs to be done. The unknown --from-imports
appears to be promising but I can't find information on how to use it.
Here is the Python code generated for the UI file:
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '.\VideoPreview.ui',
# licensing of '.\VideoPreview.ui' applies.
#
# Created: Mon May 23 10:19:15 2022
# by: pyside2-uic running on PySide2 5.13.2
#
# WARNING! All changes made in this file will be lost!
from PySide2 import QtCore, QtGui, QtWidgets
class Ui_w_video_preview(object):
def setupUi(self, w_video_preview):
w_video_preview.setObjectName("w_video_preview")
w_video_preview.resize(614, 406)
...
self.btn_open = QtWidgets.QPushButton(w_video_preview)
self.btn_open.setText("")
icon4 = QtGui.QIcon()
icon4.addPixmap(QtGui.QPixmap(":/images/VideoPreviewButtons/open_button.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.btn_open.setIcon(icon4)
...
self.retranslateUi(w_video_preview)
QtCore.QMetaObject.connectSlotsByName(w_video_preview)
def retranslateUi(self, w_video_preview):
...
from PySide2.QtMultimediaWidgets import QVideoWidget
# FOLLOWING WAS ADDED MANUALLY
from resources.icons import buttons_rc
I've excluded most of the code (since it's pretty generic) and left one example for a QPushButton
that uses an icon provided by a QRC file. The code above reported missing buttons_rc
when used like this
...
from widgets.views.VideoPreviewGenerated import Ui_w_video_preview
...
class VideoPreview(QWidget):
def __init__(self):
super(VideoPreview, self).__init__()
self.ui = Ui_w_video_preview()
self.ui.setupUi(self)
...
so the line
from resources.icons import buttons_rc
was added manually to the end of the UI generated Python code.
The generated Python code for the QRC file respectively looks like this:
# -*- coding: utf-8 -*-
# Resource object code
#
# Created: Mo Mai 23 10:18:59 2022
# by: The Resource Compiler for PySide2 (Qt v5.12.9)
#
# WARNING! All changes made in this file will be lost!
from PySide2 import QtCore
qt_resource_data = b"\
...
"
def qInitResources():
QtCore.qRegisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
def qCleanupResources():
QtCore.qUnregisterResourceData(0x01, qt_resource_struct, qt_resource_name, qt_resource_data)
qInitResources()
The UI form file contains the reference to the QRC item like this:
<widget class="QPushButton" name="btn_open">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../resources/icons/buttons.qrc">
<normaloff>:/images/VideoPreviewButtons/open_button.png</normaloff>:/images/VideoPreviewButtons/open_button.png</iconset>
</property>
<property name="iconSize">
<size>
<width>100</width>
<height>10</height>
</size>
</property>
</widget>
The QRC file is also referenced by the UI form file:
<resources>
<include location="../../resources/icons/buttons.qrc"/>
</resources>
Is this intentional that I need to manually add QRC sources as imports or is there a way to automate it?
NOTE: uic
at least for PySide2 (Qt5.x) does not offer a Python generator. I'm using the latest conda
package (from Anaconda's code-forge
channel).