QDockWidget doesn't stay on top
-
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.
-
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.
-
@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. -
@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. -
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?
-
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?
@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.