8

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.

  1. 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;
    }
    }
    
  2. Reparent:

    m_pTabBar->setParent(m_pMdiArea);
    
  3. Hiding:

    if (m_pMdiAreaTabBar != 0) m_pMdiAreaTabBar->hide();
    
  4. Signals & Slots used: QMdiArea::subWindowActivated(QMdiSubWindow*), QTabBar::currentChanged(int)

Dmitry K.
  • 313
  • 3
  • 17
  • 2
    I think I have a solution. I have found there http://qt-project.org/forums/viewthread/13140 that it is possible to get tab bar through QMdiArea.findChild(QtGui.QTabBar). So I can simply hide it. Then I can use a mix of QMdiArea and a custom tab bar layed out in a simple widget. I can also provide interface to both QMdiArea and tab bar. I think that will do the job. I have to check out. Have to post on qt-project this workaround. – Dmitry K. May 13 '13 at 23:12
  • You know, Qt is such a constructor. – Dmitry K. May 23 '13 at 11:16
  • Beware, `QMdiArea`'s `QTabBar` child widget is constructed at request, for example when you set `QMdiArea`'s view mode to `TabView`. – Dmitry K. Jun 15 '13 at 13:42
  • What are advantages of tabbed QMdiArea against QTabWidget? – Pavel Strakhov Jun 15 '13 at 15:31
  • @Riateche You can permit the user to switch between the desired mode "out of the box". There are a lot of walkarounds for this. Sometimes I like digging into something no matter whether it is full of use or nothing worth an effort, trying, testing, looking how it works for myself. – Dmitry K. Jun 15 '13 at 22:53

0 Answers0