Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Define the tab position when tabifying a QDockWidget

    General and Desktop
    2
    5
    679
    Loading More Posts
    • 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.
    • l3u_
      l3u_ last edited by l3u_

      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

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

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

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • l3u_
          l3u_ last edited by l3u_

          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 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.

          1 Reply Last reply Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            I would remove the second call of addDockWidget.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply Reply Quote 0
            • l3u_
              l3u_ last edited by

              This leads to the very same result …

              1 Reply Last reply Reply Quote 0
              • First post
                Last post