将 qtDesigner .ui 文件链接到 python/pyqt? [英] Linking a qtDesigner .ui file to python/pyqt?
问题描述
所以如果我进入 QtDesigner 并构建一个 UI,它会被保存为一个 .ui 文件.如何将其制作为 python 文件或在 python 中使用它?
So if I go into QtDesigner and build a UI, it'll be saved as a .ui file. How can I make this as a python file or use this in python?
推荐答案
另一种在代码中使用 .ui 的方法是:
Another way to use .ui in your code is:
from PyQt4 import QtCore, QtGui, uic
class MyWidget(QtGui.QWidget)
...
#somewhere in constructor:
uic.loadUi('MyWidget.ui', self)
这两种方法都不错.不要忘记,如果你使用 Qt 资源文件(非常有用)作为图标等等,你也必须编译它:
both approaches are good. Do not forget, that if you use Qt resource files (extremely useful) for icons and so on, you must compile it too:
pyrcc4.exe -o ui/images_rc.py ui/images/images.qrc
注意,uic
在编译接口时,会在.py文件的末尾添加'import images_rc',所以你必须将资源编译到这个名字的文件中,或者在生成的代码中重命名.
Note, when uic
compiles interface, it adds 'import images_rc' at the end of .py file, so you must compile resources into the file with this name, or rename it in generated code.
这篇关于将 qtDesigner .ui 文件链接到 python/pyqt?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!