Advertisement
danfalck

add_tab_and_ui.py

Jan 21st, 2012
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. from PyQt4 import QtGui,QtCore
  2. from PyQt4 import uic
  3. #from PySide import QtGui,QtCore
  4.  
  5. def getMainWindow():
  6.     "returns the main window"
  7.     # using QtGui.qApp.activeWindow() isn't very reliable because if another
  8.     # widget than the mainwindow is active (e.g. a dialog) the wrong widget is
  9.     # returned
  10.     toplevel = QtGui.qApp.topLevelWidgets()
  11.     for i in toplevel:
  12.         if i.metaObject().className() == "Gui::MainWindow":
  13.             return i
  14.     raise Exception("No main window found")
  15.  
  16. def getComboView(mw):
  17.     dw=mw.findChildren(QtGui.QDockWidget)
  18.     for i in dw:
  19.         if str(i.objectName()) == "Combo View":
  20.             return i.findChild(QtGui.QTabWidget)
  21.     raise Exception("No tab widget found")
  22.  
  23. mw = getMainWindow()
  24. tab = getComboView(getMainWindow())
  25. tab2=QtGui.QDialog()
  26. tab.addTab(tab2,"A Special Tab")
  27. uic.loadUi("/home/danfalck/Documents/freecad/taskpanel_experiments/TaskPanelforTabs.ui",tab2)
  28. tab2.show()
  29.  
  30. #tab.removeTab(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement