Loading QtDesigner's .ui files in PySide

denysonique picture denysonique · Aug 22, 2011 · Viewed 23.1k times · Source

I am looking for a simple example of how to directly load a QtDesigner generated .ui file into a Python application.

I simply would like to avoid using pyuic4.

Answer

BarryPye picture BarryPye · Aug 18, 2013

For the complete noobs at PySide and .ui files, here is a complete example:

from PySide import QtCore, QtGui, QtUiTools


def loadUiWidget(uifilename, parent=None):
    loader = QtUiTools.QUiLoader()
    uifile = QtCore.QFile(uifilename)
    uifile.open(QtCore.QFile.ReadOnly)
    ui = loader.load(uifile, parent)
    uifile.close()
    return ui


if __name__ == "__main__":
    import sys
    app = QtGui.QApplication(sys.argv)
    MainWindow = loadUiWidget(":/forms/myform.ui")
    MainWindow.show()
    sys.exit(app.exec_())