In Qt Designer app, create an interface. For example, I firstly created a form with two text widgets and then one push button.
Paste the following in the FreeCAD Python console:
from PySide import QtCore, QtGui class CalculateSum: def __init__(self): # Importing the form from Qt UI file. self.form = FreeCADGui.PySideUic.loadUi("/home/mandeep/ui-design/inputform.ui") # Setting on-click behavior of Calculate button QtCore.QObject.connect(self.form.calculateButton, QtCore.SIGNAL("clicked()"), self.accept) def accept(self): """Will be called when Calculate button is clicked""" # Take inputs from both fields. v1 = int(self.form.val1.text()) v2 = int(self.form.val2.text()) print("Sum of "+str(v1)+" and "+str(v2)+": "+str(v1+v2)) # Show up in FreeCAD. if FreeCAD.GuiUp: FreeCADGui.Control.showDialog(CalculateSum())
You will see the widget (Form) inputform.ui in the Combo View Tasks panel in FreeCAD. Enter values and click the Calculate button and the result will be printed in the Report View.
This solved my problem. Thank you!
I was trying to use this approach
https://stackoverflow.com/questions/7144313/loading-qtdesigners-ui-files-in-pyside
but it crashes the software.
LikeLike
Good to know, Gabriel.
Thanks.
LikeLike