Using Qt UI files with PySide in FreeCAD

In Qt Designer app, create an interface. For example, I firstly created a form with two text widgets and then one push button.

qt ui design

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:

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.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s