Note that there are some explanatory texts on larger screens.

plurals
  1. POUse custom tab bar with QMdiArea
    primarykey
    data
    text
    <p>I see that <code>QMdiArea</code> has a tabbed view mode. I want to be able to split the main window with two <code>QMdiArea</code> widgets and to be able to drag and drop tabs between each of them. I have already done it with a simple <code>QTabWidget</code> where I can set custom tab bar. At the same time I want to switch <code>QMdiArea</code> view mode thus using <code>QTabWidget</code> is not an option for me. But I don't see any methods to set custom tab bar within <code>QMdiArea</code>. I still have hope that it could be done. Can anyone suggest something?</p> <h3>Tested solution for Qt 4.8 (edit)</h3> <p>After some time of research I can suggest the following solution. You have to make a new class inheriting <code>QMdiArea</code>. Set its view mode to <code>TabbedView</code> to make the standart <code>QTabBar</code> to be constructed within <code>QMdiArea</code>. Then get all children and find <code>QTabBar</code> widget with <code>QString(QObject::metaObject()-&gt;className()) == "QTabBar"</code>. Hide it. You will get a blank area above the document in <code>TabbedView</code> 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.</p> <p>If you have found this post useful please vote on it. Thanks.</p> <p>Some code for example.</p> <ol> <li><p>Looking for a standart <code>QTabBar</code> within a custom mdi area in its constructor:</p> <pre><code>m_pMdiAreaTabBar = NULL; m_pMdiArea-&gt;setViewMode(QMdiArea::TabbedView); QObjectList listChildren = m_pMdiArea-&gt;children(); for (QObjectList::Iterator i = listChildren.begin(); i != listChildren.end(); ++i) { if (QString((*i)-&gt;metaObject()-&gt;className()) == "QTabBar") { m_pMdiAreaTabBar = dynamic_cast&lt;QTabBar*&gt;(*i); break; } } </code></pre></li> <li><p>Reparent:</p> <pre><code>m_pTabBar-&gt;setParent(m_pMdiArea); </code></pre></li> <li><p>Hiding:</p> <pre><code>if (m_pMdiAreaTabBar != 0) m_pMdiAreaTabBar-&gt;hide(); </code></pre></li> <li><p>Signals &amp; Slots used: <code>QMdiArea::subWindowActivated(QMdiSubWindow*)</code>, <code>QTabBar::currentChanged(int)</code></p></li> </ol>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload