PYQT4 - How do I compile and import a qrc file into my program?

前端 未结 5 1161
余生分开走
余生分开走 2021-02-01 23:05

I\'m having trouble importing a resource file. I\'m using pyqt4 with monkey studio and I am trying to import a png image. When I run the program I get an import error like

相关标签:
5条回答
  • 2021-02-01 23:54

    Open cmd (or terminal on *nix) and run

    pyrcc4 -py3 F:\computing\Payrollv22\icon.qrc -o icon_rc.py
    

    It compiled the file successfully and I was able to import the py file into my project and run it with no problem.

    0 讨论(0)
  • 2021-02-01 23:54

    There really isn't much to explain here, you have a resource file (e.g. icon.qrc), then you call pyrcc4 -o icon_rc.py icon.qrc which will create a module icon_rc.py which you then can import in your project.

    It's all documented here.

    0 讨论(0)
  • 2021-02-01 23:58

    its because when you also used pyuic5 to convert your UI to py, the resource file name from the UI sticks.

    then use

    Pyrcc5 input_file.qrc -o icons.py
    

    remove from main_script.py

    import icon_rc
    

    and use

    import icons
    

    the when calling the actual icons from the icons module, you have to look at your qrc file prefix.

    < RCC >
        < qresource
        prefix = "ico5" >
        < file > plugin.png < / file >
        < / qresource >
    < / RCC >
    

    if prefix is ico5 then you load icons with

     QtGui.QIcon(":/ico5/plugin.png")
    

    and if prefix is , lets say,

    <RCC>
        <qresource prefix="icons">
    

    then its:

      QtGui.QIcon(":/icons/plugin.png")
    
    0 讨论(0)
  • 2021-02-02 00:00

    you could try with pyside as well like:

    --- pyside-rcc -o input.qrc output.py

    0 讨论(0)
  • 2021-02-02 00:10

    In Pyqt5 this command can be used Pyrcc5 input_file.qrc -o Out_file.py

    We need to convert that qrc file into python file and then it can be imported to your code

    0 讨论(0)
提交回复
热议问题