tags:

views:

424

answers:

5

Right now I have four customized QDockWidgets on the left side of my application. When you start the application, each one is visible, but very small because of the visibility of each one. I would like for three of the QDockWidgets to nest behind one primary one to give that one priority and the entire left side of the screen.

Does anyone know how to tell QDockWidgets to nest when they are created?

+1  A: 

This is probably not possible since QDockWidgets are heavily integrated with QMainWindow.
What happens behind the scenes is that QMainWidow has a main layout which contains all the QDocksWidgets, QToolbars and the main widget.

What may be possible is to somehow make one QDockWidget replace the others or be drawn over them. You'll need to dig abit into QMainWindow code to see exactly how to do this and probably to inherit from QDockWidget which is something you usually are not supposed to do.

shoosh
A: 

Not sure exactly what you're after. Maybe you could use something like a QStackedWidget in the dock widget, and use drag and drop events to create new QDockWidgets or move the contents of a QDockWidget into a new QStackedWidget?

Reed Hedges
A: 

This can be accomplished with QMainWindow.tabifyDockWidget:

http://doc.trolltech.com/4.5/qmainwindow.html#tabifyDockWidget

This will create tabs automatically, and you can select each dock widget as needed.

brianz
A: 

If you don't want to tabify your QDockWidgets using brianz' solution, just use removeDockWidget and addDockWidget interchangeably to set the visible dock widget.

e.g. If you have dock1 and dock2:

At starup:

g_Main->addDockWidget(Qt::LeftDockWidgetArea, dock1);

On some menu action:

void MainWnd::ShowDock2(){
    g_Main->removeDockWidget(dock1);
    g_Main->addDockWidget(Qt::LeftDockWidgetArea, dock2);
    dock2->show();
}

On another menu action:

void MainWnd::ShowDock1(){
    g_Main->removeDockWidget(dock2);
    g_Main->addDockWidget(Qt::LeftDockWidgetArea, dock1);
    dock1->show();
}

Could be simplified if you derive from QMainWindow and by using a parent class for the dock widgets to automatically send out signals when one gets added to the dock to remove the others from it

Gayan
A: 

Try:

QMainWindow::setDockNestingEnabled(true);

Marinov Iván