0

In Qt Designer, I defined a couple of icons in the resource browser and I attached them to buttons and actions. The Designer preview shows the icons. Icons are stored in icons.qrc file.

But when I load the UI file :

class MyQtApp():
    def __init__(self):
        super().__init__()
        self.ui = QUiLoader().load("ui/main.ui")
        self.ui.show()

if __name__ == '__main__':
    app = QtWidgets.QApplication([])
    my_app = MyQtApp()
    app.exec_()

the icons are lost. They don't appear on the buttons.

I don't mind compiling the icons.qrc using :

pyside2-rcc.exe icons.qrc -o icons_rc.py

but how can I link the icons_rc.py to my code if I use QUiLoader().load() ?

PS: Of course, when I use both the resource and the ui compiler (pyside2-uic.exe and pyside2-rcc.exe), I don't have this issue but I prefer using QUiLoader().load() if possible.

u2gilles
  • 6,888
  • 7
  • 51
  • 75

1 Answers1

2

The only thing you have to do is to import the icons_rc.py in your main file.

Just add the statement

import icons_rc.py

In the beginning of you file and that's it. This works for me.

JeCh
  • 980
  • 1
  • 7
  • 14