qrc 文件 + ui 文件不起作用 [英] qrc file + ui file does not work
问题描述
我在使用 pyqt 时遇到了一些问题.我必须示例文件:
I have some problems with pyqt. I have to example files:
- 登录.ui
- 登录.qrc
所以,用qt设计器制作的login.ui使用了qrc文件的一些资源.qrc 有一些在 ui 文件中创建的按钮的图像.
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.
qrc 文件正在使用一个目录图像,其中按钮的图像.它仅适用于 qt 设计器.如果我在 QtCreator 的 qt 设计器中打开,在 C++ 中,它显示带有相应图标的按钮.
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.
我的python文件Login.py"是这样的:
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_())
它正在导入 ui 文件.现在的问题:
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.
我应该在我的 python 文件中做一些配置吗?我错过了什么吗?
Should I make some configuration in my python file? Am I missing something?
谢谢各位.^^
推荐答案
我认为您需要将 .qrc 文件编译为 Python 模块并将其导入以将图标加载到内存中.
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/静态/Docs/PyQt4/html/resources.html
pyrcc4
是 PyQt 等价于 Qt 的 rcc 实用程序,用于完全一样的方式.pyrcc4
读取.qrc
文件,资源文件,并生成一个只需要导入的 Python 模块通过应用程序使这些资源可用就好像它们是原始文件一样.
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.
这篇关于qrc 文件 + ui 文件不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!