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.
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_())
PySide, unlike PyQt, has implemented the QUiLoader class to directly read in .ui files. From the linked documentation,
loader = QUiLoader() file = QFile(":/forms/myform.ui") file.open(QFile.ReadOnly) myWidget = loader.load(file, self) file.close()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With