Skip to content

Dynamically load graphical interface definition

Gaël Écorchard edited this page Dec 25, 2019 · 2 revisions

In order to reduce the number of lines in macros with graphical interfaces it is better to define the graphical interface in a ui file that is loaded at runtime. Cf. https://github.com/FreeCAD/FreeCAD-macros/blob/master/FEM/FemAnimateModeShapes.FCMacro as an example.

Things to do:

  • Design you graphical interface with Qt Designer
  • Add the ui file to the __Files__ variable in the metadata
  • In the macro import FreeCADGui as gui
  • Later in the macro ui = gui.PySideUic.loadUi('relative_path_to_ui_file') or form, widget = gui.PySideUic.loadUiType('relative_path_to_ui_file')