Skip to content

Create widgets linked to a property of a DocumentObject

Gaël Écorchard edited this page Nov 27, 2023 · 1 revision

To create widgets in you dialog that are linked to a property of a DocumentObject you can use the following code for example:

doc = App.newDocument()
box = doc.addObject("Part::Box", "Box")
doc.recompute()
ui = Gui.UiLoader()

spin_box = ui.createWidget("Gui::QuantitySpinBox")
spin_box.setProperty("unit", "mm")
spin_box.setProperty("value", box.Height)
Gui.ExpressionBinding(spin_box).bind(box, "Height")
spin_box.show()