Hi Henry/Alex,

Ideally you have to import the entire generated Python file to get access to 
the resources.  You can read about it here: 
https://doc.qt.io/qtforpython-6/tutorials/basictutorial/qrcfiles.html#generating-a-python-file
So, a simple "import images.compiledresource_rc" would suffice and you should 
be able to use your resources in code.

There are also many examples in the Qt for Python 
repository<https://code.qt.io/cgit/pyside/pyside-setup.git/tree/> that makes 
use of .qrc files. 
https://doc.qt.io/qtforpython-6/examples/example_quickcontrols_gallery.html 
would be one among them.

Sincerely,
Shyamnath


Shyamnath Premnadh

Senior Software Engineer - Qt for Python

The Qt Company GmbH
Erich-Thilo-Str. 10
12489 Berlin, Germany

shyamanath.premn...@qt.io<mailto:shyamanath.premn...@qt.io>

+49 15780598679

www.qt.io<https://www.qt.io/>

Geschäftsführer: Mika Pälsi, Juha Varelius, Jouni Lintunen Sitz der 
Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B

[https://www.qt.io/]<https://www.qt.io/>
[https://www.facebook.com/qt/]<https://www.facebook.com/qt/>    
[https://twitter.com/qtproject] <https://twitter.com/qtproject>         
[https://www.linkedin.com/company/qtgroup/] 
<https://www.linkedin.com/company/qtgroup/>         
[https://www.youtube.com/QtStudios] <https://www.youtube.com/QtStudios>









________________________________
From: PySide <pyside-boun...@qt-project.org> on behalf of henry.wede--- via 
PySide <pyside@qt-project.org>
Sent: Thursday, September 28, 2023 8:17 PM
To: pyside@qt-project.org <pyside@qt-project.org>
Subject: Re: [PySide] Help importing compiled Qt resource file from subfolder

Thank you Adrian.

A typical compiled resource file for me looks like this:
qt_resource_data = b"\
{snip}
"
qt_resource_name = b"\
{snip}
"
qt_resource_struct = b"\
{snip}
"
def qInitResources():
    QtCore.qRegisterResourceData(0x03, qt_resource_struct, qt_resource_name, 
qt_resource_data)

def qCleanupResources():
    QtCore.qUnregisterResourceData(0x03, qt_resource_struct, qt_resource_name, 
qt_resource_data)

qInitResources()


So is the solution
from images.compiledresource_rc import qInitResources

Will that register the resource data without any garbage collection or other 
problems?

BTW, as much as I love Python, the way it handles modules in folder seems very 
odd to me.

Henry


On Thursday, September 28, 2023 at 08:28:36 AM MDT, Alex Strickland 
<s...@mweb.co.za> wrote:



Hi Adrian


Is that line the same as:


    images.compiledresource_rc import anyFunction


That is, just importing any function will wire up resources like icons etc? I 
am asking on behalf of a team member, I can't try it myself atm.


--

Regards

Alex




On 2023/09/28 13:34, Adrian Herrmann via PySide wrote:
Hello Henry,

for your current project structure it appears that this line in helpers.py 
would be enough for the import to work:

      from images.compiledresource_rc import someFunction

This should work regardless of the working directory, as long as helpers.py is 
imported from main.py, because the directory that main.py sits in is always 
added to PYTHONPATH.

Let us know if you have further questions or problems.
Best regards,




Adrian Herrmann

Software Engineer, Qt for Python



Qt Group
Erich-Thilo-Str. 10 12489
Berlin, Germany

adrian.herrm...@qt.io<mailto:adrian.herrm...@qt.io>

+49 1578 0598682

www.qt.io<https://www.qt.io>



Geschäftsführer: Mika Pälsi, Juha Varelius, Jouni Lintunen Sitz der 
Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B



[https://s3.eu-north-1.amazonaws.com/email-signature-tool-leroy/Qt-Group-logo-black.png]<https://www.qt.io/>
[https://s3.eu-north-1.amazonaws.com/email-signature-tool-leroy/facebook-x2-right_2023-03-01-095511_zhlr.png]<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.facebook.com%2Fqt%2F&data=05%7C01%7Cshyamnath.premnadh%40qt.io%7Cf047a276672a462320f308dbc04f88b5%7C20d0b167794d448a9d01aaeccc1124ac%7C0%7C0%7C638315220060929575%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=BvP0Pezdc1K7rTHzpL4QoMEB3LkyMcbH0J0WXiYVHHs%3D&reserved=0>
       
[https://s3.eu-north-1.amazonaws.com/email-signature-tool-leroy/twitter-x2.png] 
<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Ftwitter.com%2Fqtproject&data=05%7C01%7Cshyamnath.premnadh%40qt.io%7Cf047a276672a462320f308dbc04f88b5%7C20d0b167794d448a9d01aaeccc1124ac%7C0%7C0%7C638315220061085799%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=DsrHsdPOL%2BOL7Ugbrx0lt4jKOo1Ry1c0bOgCQGKG1ME%3D&reserved=0>
   
[https://s3.eu-north-1.amazonaws.com/email-signature-tool-leroy/linkedin-x2.png]
 
<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.linkedin.com%2Fcompany%2Fqtgroup%2F&data=05%7C01%7Cshyamnath.premnadh%40qt.io%7Cf047a276672a462320f308dbc04f88b5%7C20d0b167794d448a9d01aaeccc1124ac%7C0%7C0%7C638315220061085799%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=pLZ1b8Odo%2BdO56AcBnnlaGRy1XJKTHNdIuEe073mC5o%3D&reserved=0>
  
[https://s3.eu-north-1.amazonaws.com/email-signature-tool-leroy/youtube-x2.png] 
<https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2FQtStudios&data=05%7C01%7Cshyamnath.premnadh%40qt.io%7Cf047a276672a462320f308dbc04f88b5%7C20d0b167794d448a9d01aaeccc1124ac%7C0%7C0%7C638315220061085799%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=q50WV8U2d3sEAJ3xquPHtsJ0lCPP4ZL0O%2FmJt%2FqLtoc%3D&reserved=0>

________________________________________
Von: PySide 
<pyside-boun...@qt-project.org><mailto:pyside-boun...@qt-project.org> im 
Auftrag von henry.wede--- via PySide 
<pyside@qt-project.org><mailto:pyside@qt-project.org>
Gesendet: Montag, 25. September 2023 01:00
An: pyside@qt-project.org<mailto:pyside@qt-project.org>
Betreff: [PySide] Help importing compiled Qt resource file from subfolder

Hello,

I have spend the last few hours trying to figure this out and now I have to ask 
for some help.

My project has grown to the point where is needs to be more organized, so I am 
moving modules from one huge folder into subfolders.  I use a resource file in 
QtDesigner and then compile it resulting in a "something_rc.py".  With the "one 
huge folder" approach I just imported this file into any module that uses 
dialogs - this is the only way that the images would show up in the widgets.  
Now I am struggling to do this with the folder structure.

I made a simple example that shows the issue.  The tree is below and the 
attached zip file contains everything.

pkg
│   main.py
│   test_local.py
│
├───images
│       compiledresource_rc.py
│
└───utils
        helpers.py
        util.py
        __init__.py


Briefly, main can import test_local and util without any problems.  The issue 
is that if helpers needs to import the compiled resource file 
compiledresource_rc.  I swear that I have tried the exact syntax from different 
Internet resources and I cannot get it to work.

Can somebody please help me deal with this resource file?

Thank you for your help,
Henry







_______________________________________________
PySide mailing list
PySide@qt-project.org<mailto:PySide@qt-project.org>
https://lists.qt-project.org/listinfo/pyside



_______________________________________________
PySide mailing list
PySide@qt-project.org<mailto:PySide@qt-project.org>
https://lists.qt-project.org/listinfo/pyside

_______________________________________________
PySide mailing list
PySide@qt-project.org
https://lists.qt-project.org/listinfo/pyside

Reply via email to