How do you upload .ui files to python classes using PySide?

I used PyQt for quite some time, and all this time I used it, there was a fairly consistent programming pattern.

  • Use Qt Designer to create the .ui file.
  • Create a python class of the same type as the widget created in the .ui file.
  • When initializing the python class, use uic to dynamically load the .ui file into the class.

Is there a way to do something like this in PySide? I read the documentation and examples, and the closest thing I could find was an example of a calculator that previously rendered the .ui file into python code, which is the oldest way to do this in PyQt (why bake it in python when you can just parse ui ?)

+16
python user-interface qt pyqt pyside
Feb 15 '13 at 10:29
source share
1 answer

I do just that with PySide. :)

You use this https://gist.github.com/cpbotha/1b42a20c8f3eb9bb7cb8 (the original Sebastian Wiesner was at https://github.com/lunaryorn/snippets/blob/master/qt4/designer/pyside_dynamic.py but disappeared) - this overrides PySide.QtUiTools.QUiLoader and supplies a new loadUi() method so you can do this:

 class MyMainWindow(QMainWindow): def __init__(self, parent=None): QMainWindow.__init__(self, parent) loadUi('mainwindow.ui', self) 

When you create an instance of MyMainWindow, it will have the user interface that you created using Qt Designer.

If you also need to use custom widgets ("Promote" in Qt Designer), see this answer: https://stackoverflow.com/a/165389/

+20
Feb 15 '13 at 12:14
source share



All Articles