简体   繁体   English

qrc文件+ ui文件不起作用

[英]qrc file + ui file does not work

I have some problems with pyqt. 我有pyqt的一些问题。 I have to example files: 我必须有示例文件:

  • login.ui login.ui
  • login.qrc login.qrc

So, the login.ui, maked with the qt designer uses some resources of the qrc file. 因此,使用qt设计器的login.ui使用了qrc文件的一些资源。 The qrc have some images for the buttons created in ui file. qrc有一些用于在ui文件中创建的按钮的图像。

The qrc file is using an directory images, where's the images of the buttons. qrc文件使用的是目录图像,其中是按钮的图像。 It works only in the qt designer. 它只适用于qt设计师。 If I open in the qt designer of the QtCreator, in C++, it shows the buttons with the respective icons. 如果我在QtCreator的qt设计器中打开,在C ++中,它会显示带有相应图标的按钮。

My python file "Login.py" is like this: 我的python文件“Login.py”是这样的:

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. 它正在导入ui文件。 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? 我应该在我的python文件中进行一些配置吗? Am I missing something? 我错过了什么吗?

Thank's guys. 多谢你们。 ^^ ^^

I think you need to compile .qrc file to a Python module and import it for the icons to be loaded into memory. 我认为你需要将.qrc文件编译成Python模块并导入它以便将图标加载到内存中。

http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/resources.html 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是PyQt相当于Qt的rcc实用程序,并以完全相同的方式使用。 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. pyrcc4读取.qrc文件和资源文件,并生成一个只需要由应用程序导入的Python模块,以便使这些资源可用,就像它们是原始文件一样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM