qt的一个强大之后便是可以直观地使用 qt designer 设计界面,pyqt也可以使用这个ui文件,大大简化了ui的设计时间。
使用方法:
如果没有使用eric一类的IDE,那么可以使用命令行的方式将ui文件转化成.py文件,pyqt是自带pyuic.py这个工具的。
首先,必须在给python安装了pyqt,安装方法见http://blog.youkuaiyun.com/lainegates/article/details/8656102
然后,使用Qt Designer设计好ui文件,保存为form.ui,假设路径为D:/
最后,打开cmd,进入pyqt的uic目录,我的是C:\Python26\Lib\site-packages\PyQt4\uic,输入 "python pyuic.py -o D:/ui_form.py D:/form.ui",然后就会在form.ui所在目录生成它对应的.py文件了。
测试载入UI文件:
- class UItest(QtGui.QDialog):
- def __init__(self,parent=None):
- QtGui.QWidget.__init__(self,parent)
- self.loginGui()
- def loginGui(self):
- self.ui = Ui_Dialog()
- self.ui.setupUi(self)
- self.show()
- app = QtGui.QApplication(sys.argv)
- myqq = UItest()
- sys.exit(app.exec_())
-
NAME
-
pyuic4 - compile Qt4 user interfaces to Python code
-
SYNOPSIS
-
pyuic4 [OPTION]... FILE
-
DESCRIPTION
-
pyuic4 takes a Qt4 user interface description file and compiles it to
-
Python code. It can also show a preview of the user interface.
-
OPTIONS
-
-h, --help
-
Show a summary of the options.
-
--version
-
Display the version number of pyuic4 of the version of Qt which
-
PyQt4 was generated for.
-
-p, --preview
-
Show a preview of the UI instead of generating Python code.
-
-o, --output=FILE
-
Write the generated Python code to FILE instead of stdout.
-
-d, --debug
-
Show detailed debugging information about the UI generation
-
process.
-
-x, --execute
-
Generate extra code to test and display the class when executed
-
as a script.
-
-i, --indent=NUM
-
Set the indentation width to NUM spaces. A TAB character will be
-
used if NUM is 0 (default: 4).