PDA

View Full Version : qdockwidget tabbed movable



Alundra
25th June 2015, 03:49
Hi,
When two (or more) docks are tabified it's not possible to move the tabs.
Is it possible to make the tabs movable ? How ?
Thanks

d_stranz
26th June 2015, 00:21
Can you get a pointer to the tab widget? Call QTabWidget::setMovable() with the argument true.

Alundra
26th June 2015, 01:48
How get it since it's managed automatically by Qt when one dock is on another ?

d_stranz
26th June 2015, 17:05
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
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 );
}
}
}

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.

Kryzon
26th June 2015, 23:40
According to the source and from experiments, the native docking system only uses QTabBars for displaying the dock pages.
The docking system recycles its own QTabBars.

Setting the movable property on an internal docking QTabBar and reordering its tabs by dragging them leads to a cyclic widget repaint error. It's not supported.

d_stranz
27th June 2015, 00:43
Bummer. Don't you just hate it when that happens?

Kryzon
27th June 2015, 02:24
I like to see how other Qt programs deal (or not) with this.
Autodesk Maya, for example; it uses Qt and its native docking system, and the documentation doesn't mention tab reordering. But it's still a terrific program, so in the end it may not be something important.

http://s30.postimg.org/pmpoib0nx/Autodesk_Maya_2015_Free_Download.jpg (http://postimg.org/image/pmpoib0nx/)

- http://knowledge.autodesk.com/support/maya/learn-explore/caas/CloudHelp/cloudhelp/2015/ENU/Maya/files/Rearrange-the-interface-htm.html