I do not see a QMainWindow method that will give you the tab widget for a QDockWidget (in fact, there isn't any method that will tell you if a particular dock widget is tabbed or not). There is no signal that will tell you when a QDockWidget has been tabbed or untabbed. There is a signal that tells you if a QDockWidget has been docked or undocked: QDockWidget::topLevelChanged() and a signal to tell you if it has been moved from one area to another.
Try this: Add a slot to your MainWindow class and connect it to the topLevelChanged() signal for your dock widget. In the slot do something like this:
void MainWindow::onTopLevelChanged( bool bFloating )
{
// If the window is *not* floating, then it is docked
if ( pDock && !bFloating )
{
// Determine if other widgets are docked with this one in a tab widget
QList<
QDockWidget * > buddies
= tabifiedDockWidgets
( pDock
);
// If the list isn't empty, then the widget is part of a tab group
if ( !buddies.empty() )
{
// Find the tab widget parent
QWidget * pParent
= pDock
->parent
();
while ( pParent )
{
if ( pTab )
break;
pParent = pParent->parent();
}
if ( pTab ) // We found it
Ptab->setMovable( true );
}
}
}
void MainWindow::onTopLevelChanged( bool bFloating )
{
// If the window is *not* floating, then it is docked
QDockWidget * pDock = qobject_cast< QDockWidget * >( sender() );
if ( pDock && !bFloating )
{
// Determine if other widgets are docked with this one in a tab widget
QList< QDockWidget * > buddies = tabifiedDockWidgets( pDock );
// If the list isn't empty, then the widget is part of a tab group
if ( !buddies.empty() )
{
// Find the tab widget parent
QTabWidget * pTab = 0;
QWidget * pParent = pDock->parent();
while ( pParent )
{
pTab = qobject_cast< QTabWidget * >( pParent );
if ( pTab )
break;
pParent = pParent->parent();
}
if ( pTab ) // We found it
Ptab->setMovable( true );
}
}
}
To copy to clipboard, switch view to plain text mode
A few things I am not sure of:
1 - I do not know if QMainWindow actually uses QTabWidget as the container when dock widgets are tabified.
2 - I do not know if the container (QTabWidget or something else) is created and destroyed on-the-fly as dock widgets are tabified and un-tabified, or whether it is permanent and just hidden and shown as needed. This is why I wrote the code as shown - if the tab widget is dynamic, then it might change its pointer value.
3 - I do not know if this code will work. It is your job to find out.
Bookmarks