pyqt 使用 Qt Designer 设计的ui文件

来源:互联网 发布:win7公用网络是黑色的 编辑:程序博客网 时间:2024/05/29 08:49

qt的一个强大之后便是可以直观地使用 qt designer 设计界面,pyqt也可以使用这个ui文件,大大简化了ui的设计时间。


使用方法:

如果没有使用eric一类的IDE,那么可以使用命令行的方式将ui文件转化成.py文件,pyqt是自带pyuic.py这个工具的。

首先,必须在给python安装了pyqt,安装方法见http://blog.csdn.net/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.QMainWindow):    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_()) 


pyuic参数说明:

  1. NAME  

  2.        pyuic4 - compile Qt4 user interfaces to Python code  

  3. SYNOPSIS  

  4.        pyuic4 [OPTION]... FILE  

  5. DESCRIPTION  

  6.        pyuic4  takes  a Qt4 user interface description file and compiles it to  

  7.        Python code. It can also show a preview of the user interface.  

  8. OPTIONS  

  9.        -h, --help  

  10.               Show a summary of the options.  

  11.        --version  

  12.               Display the version number of pyuic4 of the version of Qt  which  

  13.               PyQt4 was generated for.  

  14.        -p, --preview  

  15.               Show a preview of the UI instead of generating Python code.  

  16.        -o, --output=FILE  

  17.               Write the generated Python code to FILE instead of stdout.  

  18.        -d, --debug  

  19.               Show  detailed  debugging  information  about  the UI generation  

  20.               process.  

  21.        -x, --execute  

  22.               Generate extra code to test and display the class when  executed  

  23.               as a script.  

  24.        -i, --indent=NUM  

  25.               Set the indentation width to NUM spaces. A TAB character will be  

  26.               used if NUM is 0 (default: 4).  




原创粉丝点击