Widget addition with UI object not working

Need help, or want to share a macro? Post here!
S.V. Honorio
Posts: 9
Joined: Fri Oct 11, 2019 11:50 am

Widget addition with UI object not working

Postby S.V. Honorio » Thu Nov 14, 2019 2:30 pm

Hello! I ve trying to add some interface add-ons to the software without success for the last days. I can make a window appear as a widget, but its empty and things only are added if I do it manually (which I don't want to, I want to use qt creator).

Code: Select all

import sys
from PySide import QtGui ,QtCore, QtUiTools
app = QtGui.qApp
mw = FreeCADGui.getMainWindow()
path_to_ui = "C:\Program Files\FreeCAD 0.18\Mod\Beyond Cad\Layers.ui"

app = QtGui.qApp
myNewFreeCADWidget = QtGui.QDockWidget() # create a new dckwidget
FreeCADGui.PySideUic.loadUi(path_to_ui,myNewFreeCADWidget)
mw.addDockWidget(QtCore.Qt.RightDockWidgetArea,myNewFreeCADWidget) # add the widget to the main window
S.V. Honorio
Posts: 9
Joined: Fri Oct 11, 2019 11:50 am

Re: Widget addition with UI object not working

Postby S.V. Honorio » Fri Nov 15, 2019 4:24 pm

Do you recomend to compile a python code from the .ui format instead? I was trying to make the widget manually and stuff but oh boy. I don't get to work so many modules. Even copy-pasting from the documentation.
User avatar
wandererfan
Posts: 3137
Joined: Tue Nov 06, 2012 5:42 pm

Re: Widget addition with UI object not working

Postby wandererfan » Sat Nov 16, 2019 1:41 pm

S.V. Honorio wrote:
Fri Nov 15, 2019 4:24 pm
Do you recomend to compile a python code from the .ui format instead? I was trying to make the widget manually and stuff but oh boy. I don't get to work so many modules. Even copy-pasting from the documentation.
I was hoping that a real python expert would pick this up, but FWIW...

in DraftGui.py, approx line 2440, this code displays a "Task Dialog" in the left hand panel.

Code: Select all

        self.form = QtGui.QWidget()
        self.form.setObjectName("ShapeStringTaskPanel")
        self.form.setWindowTitle(translate("draft","ShapeString"))
        layout = QtGui.QVBoxLayout(self.form)
        uiFile = QtCore.QFile(u":/ui/TaskShapeString.ui")  #this has to change if ui not in Resource file
        loader = FreeCADGui.UiLoader()
        self.task = loader.load(uiFile)
        layout.addWidget(self.task)
This isn't quite what you want to do., but maybe it gives you a hint.
S.V. Honorio
Posts: 9
Joined: Fri Oct 11, 2019 11:50 am

Re: Widget addition with UI object not working

Postby S.V. Honorio » Mon Nov 18, 2019 10:35 am

Thank you! I will give it a try.
S.V. Honorio
Posts: 9
Joined: Fri Oct 11, 2019 11:50 am

Re: Widget addition with UI object not working

Postby S.V. Honorio » Mon Nov 18, 2019 11:37 am

Still not working. An empty widget appears on the size of the window.

Code: Select all

import sys
from PySide import QtGui ,QtCore, QtUiTools
app = QtGui.qApp
mw = FreeCADGui.getMainWindow()
path_to_ui = "C:\Program Files\FreeCAD 0.18\Mod\Beyond Cad\Layers.ui"

Layers = QtGui.QDockWidget()
Layers.setObjectName("ShapeStringTaskPanel")
#Layers.setWindowTitle(translate("draft","ShapeString"))
layout = QtGui.QVBoxLayout(Layers)
uiFile = QtCore.QFile("C:\Program Files\FreeCAD 0.18\Mod\Beyond Cad\Layers2.ui")  #this has to change if ui not in Resource file
loader = FreeCADGui.UiLoader()
layout.addWidget(loader.load(uiFile))



mw.addDockWidget(QtCore.Qt.RightDockWidgetArea,Layers)