PDA

View Full Version : QUiLoader & *.qrc files?



chouqud
5th February 2014, 02:50
I would like to move away from compiling the uic and qrc files into python code through pyside-uic,.exe and pyside-rcc.exe and into loading *.ui files at runtime. I've found the QUiLoader class and that works to load the *.ui file, but one thing that is not clear to me is what mechanism loads the *.qrc file.

From the docs:
By including the user interface in the form's resources (myform.qrc), we ensure that it will be present at run-time: What is loading the myform.qrc that myform.ui is referencing?

_chouqud_

ChrisW67
5th February 2014, 04:29
Nothing loads a qrc file, it is converted to C++ code and built into your program executable. In the case of Python, the equivalent code is built by pyrcc4 (or equiv) and you import that into your script.

If you do not want to use the the resource system then the alternative is to leave the referenced files on the file system and access them directly. This is more error prone and less flexible for some purposes, but it is an option.

chouqud
5th February 2014, 13:52
Thank your for clearing that up. So when I use the pyside-uic, the resulting form_ui.py includes an 'import resource.py'. If I use the uiloader I need to manually include the 'import resource.py' before I invoke the UILoader.

Regarding that quote from the docs, I'm unclear as to what benefit I gain from including the form into the resource file. For instance, at run-time I am using python to load the *.ui file through python's io operations. What does including the ui file in the resource file do differently?

anda_skoa
5th February 2014, 15:36
Thank your for clearing that up. So when I use the pyside-uic, the resulting form_ui.py includes an 'import resource.py'.

You seem to be using resources inside your UI file, e.g. icons or something like that.

Make sure you have removed all resources from your project before running UIC.

Cheers,
_

chouqud
5th February 2014, 15:55
Make sure you have removed all resources from your project before running UIC.
Could you clarify that?

With my python workflow, I don't have a project. I have a form.ui file made with qt designer and inside this *.ui file is a section:


<resources>
<include location="../../resources/resources.qrc"/>
</resources>

And down below in a widget section for a push button, I have this entry.


<property name="icon">
<iconset resource="../../resources/resources.qrc">
<normaloff>:/image/greenlight.png</normaloff>:/image/greenlight.png</iconset>
</property>

anda_skoa
5th February 2014, 18:10
With my python workflow, I don't have a project. I have a form.ui file made with qt designer and inside this *.ui file is a section:


<resources>
<include location="../../resources/resources.qrc"/>
</resources>


Right. This triggers the resource import that you don't want. So remove it.



And down below in a widget section for a push button, I have this entry.


<property name="icon">
<iconset resource="../../resources/resources.qrc">
<normaloff>:/image/greenlight.png</normaloff>:/image/greenlight.png</iconset>
</property>

Either remove completely and set the icon in code or change to a file path.

Cheers,
_