PDA

View Full Version : addDockWidget && removeDockWidget trouble



krivenok
15th March 2006, 14:15
Hello all!

This code is a part of my MainWindow class constructor


MainWindow::MainWindow()
{
....
dock = new QDockWidget(tr("Paragraphs"), this);
QLineEdit* l = new QLineEdit(0);
dock->setWidget(l);
dock->setFeatures(QDockWidget::NoDockWidgetFeatures);
dock->setFloating(false);
addDockWidget(Qt::BottomDockWidgetArea, dock);
....
}


It works fine!

Why this code is incorrect (dock widget is invisible):


MainWindow::MainWindow()
{
....
dock = new QDockWidget(tr("Paragraphs"), this);
QLineEdit* l = new QLineEdit(0);
dock->setWidget(l);
dock->setFeatures(QDockWidget::NoDockWidgetFeatures);
dock->setFloating(false);
addDockWidget(Qt::BottomDockWidgetArea, dock);
removeDockWidget(dock); /// Remove
addDockWidget(Qt::BottomDockWidgetArea, dock); /// And add again
....
}

jpn
15th March 2006, 14:46
Removing the dock widget causes it to be hidden.

Docs say:
void QMainWindow::removeDockWidget ( QDockWidget * dockwidget )
Removes the dockwidget from the main window layout and hides it. Note that the dockwidget is not deleted.

So if you want to remove and add the same dock widget back and forth, you will have to explicitly call show() to get it visible again.