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 doesn't stay on top

QDockWidget doesn't stay on top

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.7k Views 2 Watching
  • 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.
  • A Offline
    A Offline
    Arby
    wrote on last edited by
    #1

    Hi,
    I created a simple project for testing QDockWidget functionality. I want this widget to be floating only, so I initialized it in the MainWindow constructor with the code below:

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    
        dockWidget = new QDockWidget(this);
        dockWidget->setFloating(true);
        dockWidget->setAllowedAreas(Qt::NoDockWidgetArea);
        dockWidget->setFeatures(QDockWidget::DockWidgetClosable|QDockWidget::DockWidgetMovable |
                                                     QDockWidget::DockWidgetFloatable);
    }
    

    After executing the project, the dockWidget appeared under the MainWindow and it was not on top as it is supposed to be.
    But if I call setFloating function by a pushButton like this:

    void MainWindow::on_pushButton_clicked()
    {
        dockWidget->setFloating(true);
    }
    

    The problem solves and the dockWidget returns back floating on top of the MainWindow after clicking on the button.

    I want to know what's wrong with calling "setFloating(true)" function in the MainWindow constructor and how can I set QDockWidget floating initially without having this problem?

    Thanks.

    K 1 Reply Last reply
    0
    • A Arby

      Hi,
      I created a simple project for testing QDockWidget functionality. I want this widget to be floating only, so I initialized it in the MainWindow constructor with the code below:

      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      
          dockWidget = new QDockWidget(this);
          dockWidget->setFloating(true);
          dockWidget->setAllowedAreas(Qt::NoDockWidgetArea);
          dockWidget->setFeatures(QDockWidget::DockWidgetClosable|QDockWidget::DockWidgetMovable |
                                                       QDockWidget::DockWidgetFloatable);
      }
      

      After executing the project, the dockWidget appeared under the MainWindow and it was not on top as it is supposed to be.
      But if I call setFloating function by a pushButton like this:

      void MainWindow::on_pushButton_clicked()
      {
          dockWidget->setFloating(true);
      }
      

      The problem solves and the dockWidget returns back floating on top of the MainWindow after clicking on the button.

      I want to know what's wrong with calling "setFloating(true)" function in the MainWindow constructor and how can I set QDockWidget floating initially without having this problem?

      Thanks.

      K Offline
      K Offline
      kenchan
      wrote on last edited by
      #2

      @Arby Well, assuming you have set its position somewhere sensible in relation to its parent window. You should probably call show() and raise() to make sure you can see it and it shows on top.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Arby
        wrote on last edited by
        #3

        @kenchan said in QDockWidget doesn't stay on top:

        Well, assuming you have set its position somewhere sensible in relation to its parent window. You should probably call show() and raise() to make sure you can see it and it shows on top.

        The whole project is what I mentioned and there are no sensible places in the parent window.
        I tried calling show() and raise() functions and it didn't work.

        K 1 Reply Last reply
        0
        • A Arby

          @kenchan said in QDockWidget doesn't stay on top:

          Well, assuming you have set its position somewhere sensible in relation to its parent window. You should probably call show() and raise() to make sure you can see it and it shows on top.

          The whole project is what I mentioned and there are no sensible places in the parent window.
          I tried calling show() and raise() functions and it didn't work.

          K Offline
          K Offline
          kenchan
          wrote on last edited by kenchan
          #4

          @Arby
          Well, you could just put it in the middle of the parent, or at the top left etc...
          Anyways, that is what I do with mine and it works for me.

          1 Reply Last reply
          1
          • gde23G Offline
            gde23G Offline
            gde23
            wrote on last edited by
            #5

            I've just tested your code and could not reproduce the problem.
            QDockWidget appears on top of the mainwindow on startup.
            What Qt Version / OS are you running on? I am also having some problems with dockWidgets at the moment (see here)

            As a workaround could you try to call setFloating(true) after MainWindow.show() from main. Does that change anything?

            K 1 Reply Last reply
            1
            • gde23G gde23

              I've just tested your code and could not reproduce the problem.
              QDockWidget appears on top of the mainwindow on startup.
              What Qt Version / OS are you running on? I am also having some problems with dockWidgets at the moment (see here)

              As a workaround could you try to call setFloating(true) after MainWindow.show() from main. Does that change anything?

              K Offline
              K Offline
              kenchan
              wrote on last edited by
              #6

              @gde23
              That is what i do when i float the doc widgets.

              dw->setFloating(true);
              dw->show();
              dw->raise();  
              

              My doc widgets can be set floating or docked at anytime during the execution of the app, before or after showing the main window and I don't see any difference in behaviour.
              I do not have a table like you have in any of my dock widgets, maybe that is where your problem lies.
              I am currently using Qt v5.9.2 on Windows 10 and macOs 10.14 .1.

              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