I see that QMdiArea
has a tabbed view mode. I want to be able to split the main window with two QMdiArea
widgets and to be able to drag and drop tabs between each of them. I have already done it with a simple QTabWidget
where I can set custom tab bar. At the same time I want to switch QMdiArea
view mode thus using QTabWidget
is not an option for me. But I don't see any methods to set custom tab bar within QMdiArea
. I still have hope that it could be done. Can anyone suggest something?
Tested solution for Qt 4.8 (edit)
After some time of research I can suggest the following solution. You have to make a new class inheriting QMdiArea
. Set its view mode to TabbedView
to make the standart QTabBar
to be constructed within QMdiArea
. Then get all children and find QTabBar
widget with QString(QObject::metaObject()->className()) == "QTabBar"
. Hide it. You will get a blank area above the document in TabbedView
mode. Construct you custom tab bar and reparent it to your custom mdi area. Connect signals and slots that are fired and used when the sub windows and tabs are activated. You can have your custom tab bar as a class member of your custom mdi area.
If you have found this post useful please vote on it. Thanks.
Some code for example.
Looking for a standart
QTabBar
within a custom mdi area in its constructor:m_pMdiAreaTabBar = NULL; m_pMdiArea->setViewMode(QMdiArea::TabbedView); QObjectList listChildren = m_pMdiArea->children(); for (QObjectList::Iterator i = listChildren.begin(); i != listChildren.end(); ++i) { if (QString((*i)->metaObject()->className()) == "QTabBar") { m_pMdiAreaTabBar = dynamic_cast<QTabBar*>(*i); break; } }
Reparent:
m_pTabBar->setParent(m_pMdiArea);
Hiding:
if (m_pMdiAreaTabBar != 0) m_pMdiAreaTabBar->hide();
Signals & Slots used:
QMdiArea::subWindowActivated(QMdiSubWindow*)
,QTabBar::currentChanged(int)