Linking a qtDesigner .ui file to python/pyqt?

前端 未结 12 1389
北海茫月
北海茫月 2020-11-28 01:33

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?

12条回答
  •  渐次进展
    2020-11-28 01:58

    Combining Max's answer and Shriramana Sharma's mailing list post, I built a small working example for loading a mywindow.ui file containing a QMainWindow (so just choose to create a Main Window in Qt Designer's File-New dialog).

    This is the code that loads it:

    import sys
    from PyQt4 import QtGui, uic
    
    class MyWindow(QtGui.QMainWindow):
        def __init__(self):
            super(MyWindow, self).__init__()
            uic.loadUi('mywindow.ui', self)
            self.show()
    
    if __name__ == '__main__':
        app = QtGui.QApplication(sys.argv)
        window = MyWindow()
        sys.exit(app.exec_())
    

提交回复
热议问题