Solved QDockWidget: How to let the float widget back to mainwindow when click close button.
-
How to let the float QDockWidget back to window when click close button.
-
Hi,
You can do something like that:
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { //... ui->setupUi(this); connect(ui->dockWidget, &QDockWidget::visibilityChanged, this, &MainWindow::dockWidgetVisibilityChanged); //... } void MainWindow::dockWidgetVisibilityChanged(bool visible) { if(ui->dockWidget->isFloating() && !visible){ QTimer::singleShot(100, this, &MainWindow::restoreDock); } } void MainWindow::restoreDock() { ui->dockWidget->setFloating(false); ui->dockWidget->setVisible(true); }
Note that this will not work in case you have enabled GrouppedDragging dockOption in MainWindow and you have a floating windows with several dock tabbed, as the docks are seens as "not floating".
-
It did work. Great,Thanks.