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

  • Post author:
  • Post category:其他



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 🙂



版权声明:本文为qq917141931原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。