Hypothesis: whenever several QDockWidgets are stacked one on top of another, QMainWindow automatically creates a QTabBar object with several tabs, whose properties derive from the properties of each QDockWidget. I have found elsewhere a C++ example showing, that each QTabBar->tabData(index) holds a reference to the corresponding QDockWidget, which can be dynamic_cast'ed and used.

However, I failed to find the same with PyQT, where PyQT's QTabBar.tabData(index) holds an integer, which looks suspiciously like an address or id of an object, but it is neither the address nor the id of PyQT's corresponding QDockWidget object. Therefore, having a QTabBar and its tabCloseRequested(index) signal, I can not directly get and close the corresponding QDockWidget. Whe current workaround I use is very ugly: whenever tabCloseRequested(index) signal is caught, I search among all existing QDockWidgets for the one, whose QDockWidget.windowTitle() matches the QTabBar.tabText(index), which has to be unique and machine readable. I can not even use QTabBar.tabToolTip(index) or QTabBar.tabWhatsThis(index), since it is only QTabBar.tabText(index) which is inherited from QDockWidget when QMainWindow actually creates a QTabBar.

1) Has anybody solved this problem with PyQT?
2) Is there any way to control (or at least, to be notified) when QMainWindow actually creates a QTabBar?
3) Is there a way to identify QDockWidget by QTabBar and index of the tab? Is there a way to decipher QTabBar.tabData(index) PyQT uses?