0

I have a QDockWidget class and a QMainWindow:

// docker.hpp
class Docker : public QDockWidget
{
    Q_OBJECT
public:
    Docker(QString title, QWidget* parent = 0);
}

// docker.cpp
Docker::Docker(QString title, QWidget* parent): QDockWidget(title, parent)
{
    QWidget* widget = new QWidget(this);
    widget.setMinimumSize(200, 200);
    setWidget(widget);
    widget->setStyleSheet("border:5px solid gray;");

    setAllowedAreas(Qt::AllDockWidgetAreas);
}

// mainwindow.hpp
class MainWindow : public QMainWindow
{
    Q_OBJECT
public:
    MainWindow(QWidget* parent);
private slots:
    void createDockers();
};

// mainwindow.cpp
MainWindow::MainWindow(QWidget* parent): QMainWindow(parent)
{
    setDockOptions(dockOptions() |
               QMainWindow::AllowTabbedDocks |
               QMainWindow::GroupedDragging);

    // The following line of code does not change the situation.
    // setTabPosition(Qt::RightDockWidgetArea, QTabWidget::East);

    // There are some other codes which connect a button to the void createDockers() method
}

void createDockers()
{
    Docker* dock = new Docker("Docker", this);
    dock->setFloating(true);
    dock->show();
}

I am able to create two Dockers with clicks of the button mentioned above. Two QDockWidgets

However, when I drag one QDockWidget onto the other, the border disappears and no tabs show up: Merges QDockWidgets

I am expecting the following to happen: (Achieved by spawning several QDockWidgets) Expected behaviour I am also noticing that one of the QDockWidgets did not vanish. Instead, it merged back to the MainWindow. This only happens if they are the "first two" QDockWidgets.

What caused this problem and how to solve it? I am trying to mimic this project.

Henricus V.
  • 898
  • 1
  • 8
  • 29

1 Answers1

1

I guess it's linked to the QMainWindow::GroupedDragging option. I'm pretty sure it should work well without it (I mean for the not showing tab issue). Do you have restrictions on dock position somewhere else? The documentation implies it could create issues: http://doc.qt.io/qt-5/qmainwindow.html#DockOption-enum

For the style issue, you may need to redefine it on tab event, because once tabbed, the widget may inherit the tab style instead of the dock widget style you defined (not certified at all ^^)

Last guess/thing you can try, is to start with the dock tabbed and not floating to see if you have any new bahaviour, it was what I was doing in a previous project and it was working pretty well.

Sorry but no other ideas for the moment.

Mikitori
  • 589
  • 9
  • 21
  • Disabling `QMainWindow::GroupedDragging` also disables tabs, which is what I am trying to achieve. I do not have any restrictions on dock position elsewhere. – Henricus V. May 03 '16 at 00:20
  • I think GroupedDragging implies Tabs, but it is not mandatory option. If I remember well, what I was doing was creating all dock widgets, and then put them in tabs thanks to: `mainWindow->tabifyDockWidget(prevDock, dock);` – Mikitori May 03 '16 at 08:18
  • You may also check those links to give you ideas: [link1](http://stackoverflow.com/questions/17621611/tabify-3-qdockwidget) and [link2](http://stackoverflow.com/questions/28151738/qdockwidget-tabify-splitdockwidget-weird-behavior-bug) – Mikitori May 03 '16 at 08:21