Search code examples
qtpysideqt-designer

broken image paths using pyside and QtDesigner


I'm styling some checkboxes in QtDesigner with some custom background images but I'm finding that when I load the .ui file in pyside, the images don't show up. Presumably there is a path problem. Below is an image of my file structure and the Python script that calls the .ui file is test.py.

file structure

Also here is the contents of images.qrc

<RCC>
  <qresource>
    <file>B_active.png</file>
    <file>Button_down_icon.png</file>
    <file>Button_up_icon.png</file>
    <file>B_inactive.png</file>
    <file>A_inactive.png</file>
    <file>A_active.png</file>
    <file>R_icon.png</file>
    <file>toolbar_bg.png</file>
  </qresource>
</RCC>

and also the style that references the images:

#A_button_grp QRadioButton{
    background-image: url(:/A_inactive.png);
}
#A_button_grp QRadioButton:checked{
    background-image: url(:/A_active.png);
}

What should I be doing differently here?


Solution

  • It looks like you need to compile the resource module:

    pyside-rcc -o resource_rc.py src/images.qrc
    

    Note that if ms_image_viewer.py was generated by pyside-uic, the resource module must be named resource_rc.py and saved in the same directory.