Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDockWidget: How to let the float widget back to mainwindow when click close button.
Forum Updated to NodeBB v4.3 + New Features

QDockWidget: How to let the float widget back to mainwindow when click close button.

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 690 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • brucezcgB Offline
    brucezcgB Offline
    brucezcg
    wrote on last edited by
    #1

    How to let the float QDockWidget back to window when click close button.

    1 Reply Last reply
    0
    • Gojir4G Offline
      Gojir4G Offline
      Gojir4
      wrote on last edited by Gojir4
      #2

      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".

      1 Reply Last reply
      2
      • brucezcgB Offline
        brucezcgB Offline
        brucezcg
        wrote on last edited by
        #3

        It did work. Great,Thanks.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved