Use the dedicated tab bar with QMdiArea

I see that QMdiArea has a tabbed view. I want to be able to split the main window with two QMdiArea widgets and be able to drag tabs between each of them. I already did this with a simple QTabWidget , where I can set a custom tab bar. At the same time, I want to switch the QMdiArea view QMdiArea , so using QTabWidget is not an option for me. But I do not see any methods for customizing the custom tab bar within QMdiArea . I still hope this can be done. Can anyone suggest something?

Tested solution for Qt 4.8 (edit)

After some time of research, I can offer the following solution. You must create a new class that inherits QMdiArea . Set the view mode to TabbedView so that a standard QTabBar created within QMdiArea . Then load all the children and find the QTabBar widget with QString(QObject::metaObject()->className()) == "QTabBar" . To hide. You will get a blank area above the document in TabbedView mode. Create a custom tab bar and place it in your own mdi area. Connect the signals and slots that are triggered and used when auxiliary windows and tabs are activated. You can create your own tab bar as a member of the class of your user area mdi.

If you found this post helpful, vote for it. Thanks.

Some code examples.

  • Search for a standard QTabBar in the QTabBar user 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 and slots used: QMdiArea::subWindowActivated(QMdiSubWindow*) , QTabBar::currentChanged(int)

+4
source share

Source: https://habr.com/ru/post/1480587/


All Articles