⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

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 have dock1 and dock2, and I create a new QDockWidget, and tabify it via tabifyDockWidget(dock1, newDock), it appears right of dock2, not dock1.

    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

  • Lifetime Qt Champion


    What version of Qt are you using ?
    Can you provide a minimal compilable example that shows that behaviour ?

  • Here's a minimalistic example:


    #include <QApplication>
    #include "MainWindow.h"
    int main(int argc, char *argv[])
        QApplication app(argc, argv);
        MainWindow mainWindow;
        return app.exec();


    #include <QMainWindow>
    class MainWindow : public QMainWindow


    #include "MainWindow.h"
    #include <QDockWidget>
        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 and dock2 are added and tabified. As expected, the dock2 tab appears right of the dock1 tab. After tabifying the new newDock, the tab is added right of the dock2 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.

  • Lifetime Qt Champion

    I would remove the second call of addDockWidget.

  • This leads to the very same result …

Log in to reply