PDA

View Full Version : QDockWidget: Creating more than one docking widget breaks the application



tuli
9th July 2018, 00:18
Hey,


One again QDockingWidget is keeping me awake at night. It's truly a freakish beast to say the least.

So basically I have a QMainWindow that creates two harmless docking widgets, and then floats them. It doesnt matter if I float them or attach them though.
If I create only ONE docking widget everything is fine. If I dare to create TWO or more however, everything blows up spectacularly. Namely, the docking widget freakishly creates a new QMainWindow (?) lives in that, breaking everything.


12895

I have boiled down the issue to this testcase.


class MainWindowBroken : public QMainWindow
{
Q_OBJECT

public:

MainWindowBroken(QWidget *parent = 0) : QMainWindow(parent)
{
setDockOptions(QMainWindow::AnimatedDocks | QMainWindow::AllowTabbedDocks | QMainWindow::GroupedDragging);

//creating only one dock-widget works fine. creating two breaks everything.

auto a = create_dock();
a->show();
auto b = create_dock();
b->show();
}


QDockWidget* create_dock()
{
auto dock = new QDockWidget(this);
auto child = new QTableWidget(dock);
dock->setWidget(child);
dock->setFloating(true);
return dock;
}
};



System: Ubuntu 17.04, Qt5.11, QtCreator latast.


Working with Qt is really a pleasure, until you poke at the docking system.

Added after 14 minutes:

Ok, I can shine some more light on this. The problem only occurs when either QMainWindow::AllowTabbedDocks or QMainWindow::GroupedDragging or both are set.

The freakish merging happens when two docking widgets are shown, and one is dragged on top of the other (in which case the drop target seems to self-convert to a new QMainWindow) ... ... but ONLY if the two floating docking widgets have never been attached to the QMainWindow!
If you mange to separately drag them into the QMainWindow once, then you can float them again and now the issue doesnt occur anymore.


If I show two docking widgets, they initially appear both at (0,0), so when I drag one they immediately merge and the bug occurs. I have to move the second docking widget away from the other one, so that I can then separately attach and re-float them to mitigate the problem.



auto a = create_dock();
a->show();
auto b = create_dock();
b->move(333,333); //...
b->show();


What a freakshow...

Added after 6 minutes:

lol, and here the fixed code that mitigates the problem by programatically attaching and re-floating the QDockWidgets.



auto a = create_dock();
auto b = create_dock();

a->show();
b->show();

addDockWidget(Qt::BottomDockWidgetArea, a);
a->setFloating(true);
addDockWidget(Qt::BottomDockWidgetArea, b);
b->setFloating(true);


Please tell me I have gone crazy and there is a sane explanation for all this...