QDockWidget does not stay on the right when QMainWindow resizes
-
Hi all,
I have a QMainWindow with several QDockWidget objects in it. One of them is supposed to have fixed sized and stay on the right, and when I launch the application this does happen. But when I resize the QMainWindow (or maximize it) there appears a space between this QDockWidget and the rightmost part of the QMainWindow. The same thing happens if I put the QDockWidget on the left.
See this video to better understand what I mean:
https://drive.google.com/open?id=1Ho42-zurEABTwSPETnxCtqdtynexaALgAs you can see, after I make the QDockWidget float and then dock it back in the QMainWindow, it all works as I would like it to from the beginning.
Any idea if this is a configuration I am missing somewhere? I guess the QDockWidget itself wouldn't be the problem but...
Thank you and cheers,
Vítor -
Hi,
What version of Qt are you using ?
What exact OS ?
Can you provide a minimal compilable example that reproduce that behaviour ? -
Hi SGaist,
Thanks for your time.
The OS is linux and if I do uname --all I get:
Linux ws-vitor 4.18.0-20-generic #21~18.04.1-Ubuntu SMP Wed May 8 08:43:37 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
I am running this under xubuntu.
The Qt version is that of the system: 5.9.5
I've indeed managed to put up an example where this happens. It follows our gui, but simpler with only two tabs and a "Status" that we want to have on the right.
Here you go:#ifndef TESTGUI_H #define TESTGUI_H #include <QMainWindow> #include <QDockWidget> class TestGui : public QMainWindow { public: TestGui() { setDockOptions(QMainWindow::AnimatedDocks | QMainWindow::AllowTabbedDocks); QDockWidget* dockwidget = new QDockWidget("Tab #1"); dockwidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); dockwidget->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable); dockwidget->setMinimumWidth(1000); addDockWidget(Qt::TopDockWidgetArea, dockwidget); QDockWidget* prevdockwidget = dockwidget; dockwidget = new QDockWidget("Tab #2", this); dockwidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); dockwidget->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable); dockwidget->setMinimumWidth(1000); addDockWidget(Qt::TopDockWidgetArea, dockwidget); tabifyDockWidget(prevdockwidget, dockwidget); // Problematic component dockwidget = new QDockWidget(tr("Status"), this); dockwidget->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); dockwidget->setFeatures(QDockWidget::DockWidgetFloatable | QDockWidget::DockWidgetMovable); dockwidget->setMinimumWidth(160); dockwidget->setMaximumWidth(160); dockwidget->setAllowedAreas(Qt::AllDockWidgetAreas); addDockWidget(Qt::RightDockWidgetArea, dockwidget); setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea); resize(1100, 700); } ~TestGui() = default; }; #endif // TESTGUI_H
If you maximize the window, the status stays basically in the middle instead of going all the way to the right.
Thanks a lot again. -
Do you mean it stays locked on the left side of the right dock panel ?
-
@SGaist said in QDockWidget does not stay on the right when QMainWindow resizes:
u mean it stays locked o
Not that it stays on the left: that's where I want to have it.
The problem is that it doesn't maintain its size: it becomes very wide, instead of keeping the 160 I wanted. And if you un-dock it and dock it back in again it will now have the proper size. I want to happen default when I resize (maximize) the main window.