Hi Werner,

Thanks for the reply and guide. Only one thing I'm confused, regarding to set it as right docked window as I did before like below:

FCmw.addDockWidget(QtCore.Qt.RightDockWidgetArea, menuFreeCADWidget)

But then, if you suggest to assign,

 FCmw = getMainWindow()

Then, FCmv has no longer the feature to be set as right dock or other configuration, how do I achieve that?


Thanks in advance.

-alfa-


On Wednesday, January 15, 2014 7:06 PM, Werner (GMX) <werner.wm.mayer@gmx.de> wrote:
Hi,

       menuFreeCADWidget = QtGui.QDockWidget() # create a new dckwidget
       menuFreeCADWidget.ui = menu.Ui_MainWindow()
       menuFreeCADWidget.ui.setupUi(menuFreeCADWidget)
That's wrong. You create an instance of QDockWidget but Ui_MainWindow expects an instance of QMainWindow in its setupUi method.
So, you have to write:

menuFreeCADWidget = QtGui.QDockWidget() # create a new dockwidget
menuFreeCADWidget.ui = menu.Ui_MainWindow()
mw = QtGui.QMainWindow()
menuFreeCADWidget.ui.setupUi(mw)
menuFreeCADWidget.setWidget(mw)

Then FCmw = app2.activeWindow() is not very reliable because the active window can also be a dialog under circumstances. Here you better use:

def getMainWindow():
    toplevel = QtGui.qApp.topLevelWidgets()
    for i in toplevel:
        if i.metaObject().className() == "Gui::MainWindow":
            return i
    raise Exception("No main window found")

FCmw = getMainWindow()



Am 15.01.2014 10:56, schrieb alfa:
Hi again,

..and I'm on development version by the way.
See also this thread: http://forum.freecadweb.org/viewtopic.php?f=10&t=5303&start=70

Cheers,
Werner



Thanks in advance.

-alfa-



On Wednesday, January 15, 2014 5:34 PM, Werner (GMX) <werner.wm.mayer@gmx.de> wrote:
Hi alfa,

I do not understand how this is related to FreeCAD. The code you attached works pretty well for me. And creating an instance of the form:
mw=QtGui.QMainWindow()
ui=Ui_MainWindow()
ui.setupUi(mw)
mw.show()

works for me, too. In case you want to embed this into FreeCAD's main window then the relevant code part is missing.

BTW, in the development branch we currently move from PyQt to PySide. So, in the long-term you may have to use PySide, too.

Cheers,
Werner


Am 15.01.2014 03:59, schrieb alfa:
Dear all,

I have a problem regarding adding a docked widget/window that was generated from Qt designer to the FreeCAD. 

The QtDesigner code(UI) is rather simple as below but then, it complains about the interfaces of setCentralWidget(), setMenuBar(), setStatusBar(), addToolBar() from MainWindow object. If I comment these four methods/functions, I won't get what I want in terms of the GUI features:

    from PyQt4 import QtCore, QtGui

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    _fromUtf8 = lambda s: s

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(737, 717)
        self.centralWidget = QtGui.QWidget(MainWindow)
        self.centralWidget.setObjectName(_fromUtf8("centralWidget"))
        self.formLayout = QtGui.QFormLayout(self.centralWidget)
        self.formLayout.setObjectName(_fromUtf8("formLayout"))
        self.pushButton = QtGui.QPushButton(self.centralWidget)
        self.pushButton.setObjectName(_fromUtf8("pushButton"))
        self.formLayout.setWidget(0, QtGui.QFormLayout.SpanningRole, self.pushButton)
        self.textEdit = QtGui.QTextEdit(self.centralWidget)
        self.textEdit.setObjectName(_fromUtf8("textEdit"))
        self.formLayout.setWidget(1, QtGui.QFormLayout.SpanningRole, self.textEdit)
        self.textBrowser = QtGui.QTextBrowser(self.centralWidget)
        self.textBrowser.setObjectName(_fromUtf8("textBrowser"))
        self.formLayout.setWidget(3, QtGui.QFormLayout.SpanningRole, self.textBrowser)
        self.pushButton_2 = QtGui.QPushButton(self.centralWidget)
        self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
        self.formLayout.setWidget(2, QtGui.QFormLayout.SpanningRole, self.pushButton_2)
        self.pushButton_3 = QtGui.QPushButton(self.centralWidget)
        self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
        self.formLayout.setWidget(5, QtGui.QFormLayout.SpanningRole, self.pushButton_3)
        self.pushButton_4 = QtGui.QPushButton(self.centralWidget)
        self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
        self.formLayout.setWidget(6, QtGui.QFormLayout.SpanningRole, self.pushButton_4)
        MainWindow.setCentralWidget(self.centralWidget)
        self.menuBar = QtGui.QMenuBar(MainWindow)
        self.menuBar.setGeometry(QtCore.QRect(0, 0, 737, 23))
        self.menuBar.setObjectName(_fromUtf8("menuBar"))
        MainWindow.setMenuBar(self.menuBar)
        self.mainToolBar = QtGui.QToolBar(MainWindow)
        self.mainToolBar.setObjectName(_fromUtf8("mainToolBar"))
        MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
        self.statusBar = QtGui.QStatusBar(MainWindow)
        self.statusBar.setObjectName(_fromUtf8("statusBar"))
        MainWindow.setStatusBar(self.statusBar)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowTitle(QtGui.QApplication.translate("MainWindow", "MainWindow", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton.setText(QtGui.QApplication.translate("MainWindow", "Data", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_2.setText(QtGui.QApplication.translate("MainWindow", "Result", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_3.setText(QtGui.QApplication.translate("MainWindow", "Adjustment", None, QtGui.QApplication.UnicodeUTF8))
        self.pushButton_4.setText(QtGui.QApplication.translate("MainWindow", "Action - TBD", None, QtGui.QApplication.UnicodeUTF8))

Any helps or ideas are highly appreciated. Thanks in advance.

P/S: I followed this link by the way(http://www.freecadweb.org/wiki/index.php?title=PyQt).

-alfa-




------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk


_______________________________________________
Free-cad-development mailing list
Free-cad-development@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/free-cad-development


------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk

_______________________________________________
Free-cad-development mailing list
Free-cad-development@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/free-cad-development




------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today.
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk

_______________________________________________
Free-cad-development mailing list
Free-cad-development@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/free-cad-development