2017-03-06 128 views
1

屬性我有一個母體結構象下面這樣:訪問對象從父

  • 主窗口(的QMainWindow)
    • Form1中(QWidget的)
      • 窗口2(QWidget的)

當我調用form2時,是否可以訪問mainwindow的對象屬性?

例如。

# I'm in form1, calling form2, and i need add 
# form2 in mdiArea from mainwindow 

cad = Form2(self) 
self.parent().mdiArea.addSubWindow(cad) 
cad.showMaximized() 

我的代碼返回以下錯誤消息:

unhandled AttributeError 
"'builtin_function_or_method' object has no attribute 'addSubWindow'" 

回答

0

mdiAreaQMdiSubWindow的方法。您需要訪問它:

self.parent().mdiArea().addSubWindow(cad) 

Docs