Python code generation with pyside-uic

前端 未结 8 1163
野的像风
野的像风 2020-12-01 12:18

How can I generate python code from a QtDesigner file ? I found pyside-uic but I can\'t find an example for the syntax. I run win7 and pythonxy with spyder.

8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 13:20

    Just tried Pyside's QUILoader, works fine:

    from PySide import QtGui  
    from PySide import QtCore
    from PySide import QtUiTools
    
    class MyWidget(QtGui.QMainWindow):
        def __init__(self, *args):  
           apply(QtGui.QMainWindow.__init__, (self,) + args)
    
           loader = QtUiTools.QUiLoader()
           file = QtCore.QFile("pyside_ui_qtdesigner_form_test.ui")
           file.open(QtCore.QFile.ReadOnly)
           self.myWidget = loader.load(file, self)
           file.close()
    
           self.setCentralWidget(self.myWidget)
    
    if __name__ == '__main__':  
       import sys  
       import os
       print("Running in " + os.getcwd() + " .\n")
    
       app = QtGui.QApplication(sys.argv)  
    
       win  = MyWidget()  
       win.show()
    
       app.connect(app, QtCore.SIGNAL("lastWindowClosed()"),
                   app, QtCore.SLOT("quit()"))
       app.exec_()
    

    I used Eclipse and QTDesigner to create the .ui file (right-click on module, "New -> Other..", choose "Qt Designer -> Qt Designer Form"). No explicit uic call is needed.

提交回复
热议问题