PySide Advanced Examples

From FreeCAD Documentation
Jump to navigation Jump to search
This page is a translated version of the page PySide Advanced Examples and the translation is 9% complete.
Other languages:
English • ‎français • ‎italiano • ‎русский


The purpose of this page is to cover advanced level examples of the PySide GUI manager (there are accompanying pages PySide Beginner Examples and PySide Intermediate Examples).

By using the PySide module from inside FreeCAD, you have full control over its interface. You can for example:

  • Add your own panels, widgets and toolbars
  • Add or hide elements to existing panels
  • Change, redirect or add connections between all those elements

Create Reference for the Main Window


import sys
from PySide import QtGui ,QtCore 
app = QtGui.qApp
mw = FreeCADGui.getMainWindow()

Browse the Children of the Main Window


for child in mw.children():

The widgets in a Qt interface are usually nested into "container" widgets, so the children of our main window can themselves contain other children. Depending on the widget type, there are a lot of things you can do. Check the API documentation to see what is possible.

Add New Widget Manually


myWidget = QtGui.QDockWidget()

You could then add stuff directly to your widget:

myWidget.setObjectName("my Nice New Widget")
label.setGeometry(QtCore.QRect(2,50,200,24))  # sets its size

Add New Widget by Creating UI Object


class myWidget_Ui(object):
  def setupUi(self, myWidget):
    myWidget.setObjectName("my Nice New Widget")

    self.label = QtGui.QLabel(myWidget) # creates a label
    self.label.setGeometry(QtCore.QRect(50,50,200,24)) # sets its size



app = QtGui.qApp
FCmw = app.activeWindow()
myNewFreeCADWidget = QtGui.QDockWidget() # create a new dckwidget
myNewFreeCADWidget.ui = myWidget_Ui() # load the Ui script
myNewFreeCADWidget.ui.setupUi(myNewFreeCADWidget) # setup the ui