Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qrc file + ui file does not work

Tags:

python

qt

pyqt

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

  • login.ui
  • login.qrc

So, the login.ui, maked with the qt designer uses some resources of the qrc file. The qrc have some images for the buttons created in ui file.

The qrc file is using an directory images, where's the images of the buttons. It works only in the qt designer. If I open in the qt designer of the QtCreator, in C++, it shows the buttons with the respective icons.

My python file "Login.py" is 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()
    ui.show()
    sys.exit(app.exec_())

It's importing the ui file. Now the problem:

When I run the program, the icons don't show. The files are setup in the correct folders. But when I run the app, the icons don't appears.

Should I make some configuration in my python file? Am I missing something?

Thank's guys. ^^

like image 408
Andrey Luiz Avatar asked Oct 16 '25 02:10

Andrey Luiz


1 Answers

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

http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/resources.html

pyrcc4 is PyQt’s equivalent to Qt’s rcc utility and is used in exactly the same way. pyrcc4 reads the .qrc file, and the resource files, and generates a Python module that only needs to be import ed by the application in order for those resources to be made available just as if they were the original files.

like image 172
warvariuc Avatar answered Oct 17 '25 14:10

warvariuc