Dragging QDockWidgets between QMainWindows
Hello everyone,
I want to create an application with two windows. One of them is a QMainWindow containing QDockWidgets. I want these DockWidgets to be draggable into the second window. How can that be done? Is there a simple way to reparent the DockWidgets when dragging over second window? Or can the DockWidgets be configured to accept the second window as DockArea?
thanks!
Felix
Re: Dragging QDockWidgets between QMainWindows
I found a solution :) it still has to be "beautified", but it's working!
Code:
void MainWindow::CreateDockWidgets()
{
dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
<< "John Doe, Harmony Enterprises, 12 Lakeside, Ambleton"
<< "Jane Doe, Memorabilia, 23 Watersedge, Beaton"
<< "Tammy Shea, Tiblanka, 38 Sea Views, Carlton"
<< "Tim Sheen, Caraba Gifts, 48 Ocean Way, Deal"
<< "Sol Harvey, Chicos Coffee, 53 New Springs, Eccleston"
<< "Sally Hobart, Tiroli Tea, 67 Long River, Fedula");
dock->setWidget(customerList);
dock
->setFeatures
(dock
->features
() & ~
QDockWidget::DockWidgetFloatable);
addDockWidget(Qt::RightDockWidgetArea, dock);
viewMenu->addAction(dock->toggleViewAction());
connect(dock, SIGNAL(topLevelChanged(bool)) , this, SLOT(dragStarted(bool)));
connect(dock, SIGNAL(dockLocationChanged (Qt::DockWidgetArea)) , this, SLOT(dragEnded()));
//... more dock widgets
}
void MainWindow::dragStarted(bool started)
{
if(started)
{
if(QDockWidget* dock
= qobject_cast<QDockWidget
*>
(sender
())) dw = dock;
else
dw = NULL;
}
}
void MainWindow
::enterEvent(QEvent* event
) {
if(dw && dw->parent() != this)
{
addDockWidget(Qt::RightDockWidgetArea, dw);
dw = NULL;
}
}
void MainWindow::dragEnded()
{
dw = NULL;
}
Re: Dragging QDockWidgets between QMainWindows
hi ...
i too have same requirement , i have one mainwindow and 4 dockwidgets ,and there is no central widgets also, and all dockwidgets should be floatable , movable ,draggable to all areas , so any idea how i can proceed ..................
thank u in advance ,,,:)
Re: Dragging QDockWidgets between QMainWindows
Hi,
you set the central widget explicitly to NULL. Then you enable DockNesting and that should be all for your requirements...
just put these lines in your mainwindow constructor:
Code:
setDockNestingEnabled(true);
setCentralWidget(0);
hope that helps...
Felix