Qrc file + ui not working

I have some problems with pyqt. I have example files:

  • login.ui
  • login.qrc

So login.ui created with qt constructor uses some of the qrc file resources. Qrc has several images for buttons created in ui file.

The qrc file uses directory images in which button images are displayed. It only works in qt design. If I open in qt designer QtCreator, in C ++, it shows buttons with corresponding icons.

My python file "Login.py" looks like this:

from PyQt4 import QtGui, uic
import sys

class Form(QtGui.QDialog):

    def __init__(self, parent = None):
        QtGui.QDialog.__init__(self, parent)
        uic.loadUi("login.ui", self)

if __name__ == "__main__":    
    app = QtGui.QApplication(sys.argv)    
    ui = Form()


Imports a ui file. Now the problem:

When I run the program, the icons are not displayed. The files are configured in the correct folders. But when I run the application, the icons are not displayed.

Do I have to do some configuration in my python file? Did I miss something?

Thanks guys. ^^


source to share

1 answer

I think you need to compile the .qrc file into a Python module and import it to load the icons into memory.



is PyQts, the equivalent of the Qts rcc utility, and is used in exactly the same way. pyrcc4

reads the file .qrc

and the resource files and generates a Python module that only needs to be imported on request so that these resources are available just as if they were source files.



All Articles