我开始写我的第一个PyQT应用程序(PyQT只用于处理GUI),似乎好的工具链是:QtDesigner来生成.ui和处理资源和一些IDE,可以设置QtDesigner来编辑它们。我使用Eclipse,因为它是高度可定制的。
您可以通过在应用程序启动,安装或任何其他时间按照这样做在需求情况下编译.qrc和.ui:
os.system("pyrcc4.exe -o ui/images_rc.py ui/images/images.qrc")
uic.compileUiDir(appDir + '/ui', True)
然后以这种方式使用生成的类:
class MyMainWindow(QtGui.QMainWindow):
def __init__(self, owner):
QtGui.QMainWindow.__init__(self)
# 'Ui_MyMainWindow' is the class, that was generated by uic,
# naming convention is: 'Ui_' plus the name of root widget in designer
self.ui = Ui_MyMainWindow()
self.ui.setupUi(self)
或者您可以在容器中直接加载.ui:
QtGui.QMainWindow.__init__(self)
self.ui = None
uic.loadUi('MyMainWindowUI.ui', self.ui)
#now you have the instance of Ui_MyMainWindow in s