[转]如何在pyqt中使用qt的ui(来自…

在QtDesigner创建的UI文件通常保存为.ui格式。要将其转换为Python文件或在Python中使用,可以使用两种方法。一种是通过uic编译器将.ui文件转换为.py文件,同时注意如果使用了QT资源文件(如图标),必须一同编译,并确保在生成的.py文件末尾有'import images_rc'的导入语句。

question

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?


best answer

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)

both approaches are good. Do not forget, that if you use QT recource files (extremely useful) for icons and so one, you must compile it too:


pyrcc4.exe -o ui/images_rc.py ui/images/images.qrc

Note, when uic compiles interface, it adds 'import images_rc' at the end of .py file, so you must compile recources into the file with this name (yekk...), or rename it in generated code (boo..). If you'd fugure out a workaround for it, tell me, plz :)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值