Define the tab position when tabifying a QDockWidget
-
Hi :-)
When I tabify a
QDockWidget
, it's always added as the last tab. E. g. if I havedock1
anddock2
, and I create a newQDockWidget
, and tabify it viatabifyDockWidget(dock1, newDock)
, it appears right ofdock2
, notdock1
.Is there a way to define where the tab should appear (I would suppose to see it next to the one it was tabified with)? Or is it possible to programmatically move the tab to where it should be (like it can be done via drag and drop)?
Thanks for all help!
Cheers, Tobias -
Hi,
What version of Qt are you using ?
Can you provide a minimal compilable example that shows that behaviour ? -
Here's a minimalistic example:
main.cpp:
#include <QApplication> #include "MainWindow.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); MainWindow mainWindow; mainWindow.show(); return app.exec(); }
MainWindow.h:
#include <QMainWindow> class MainWindow : public QMainWindow { Q_OBJECT public: MainWindow(); };
MainWindow.cpp:
#include "MainWindow.h" #include <QDockWidget> MainWindow::MainWindow() { QDockWidget *dock1 = new QDockWidget(tr("Dock 1"), this); dock1->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); addDockWidget(Qt::TopDockWidgetArea, dock1); QDockWidget *dock2 = new QDockWidget(tr("Dock 2"), this); dock2->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); addDockWidget(Qt::TopDockWidgetArea, dock2); tabifyDockWidget(dock1, dock2); QDockWidget *newDock = new QDockWidget(tr("New Dock"), this); newDock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); addDockWidget(Qt::TopDockWidgetArea, newDock); tabifyDockWidget(dock1, newDock); }
First,
dock1
anddock2
are added and tabified. As expected, thedock2
tab appears right of thedock1
tab. After tabifying the newnewDock
, the tab is added right of thedock2
tab, and not (as at least I would expect it) right of the dock it was tabified with (dock1
).Happens at least since Qt 5.6, and also with Qt 5.12.4 that I'm currently using.
-
I would remove the second call of addDockWidget.