Qt: Drag & Drop Widgets to Achieve Arbitrary Layout (Split) like in Eclipse
Asked Answered
K

1

3

I am aware of dock widgets, splitters, etc. Still I wonder, if it's possible to create flexible splitting system like in Eclipse: when any widget just keeps splitting either vertically or horizontally depending on the position of the cursor during dragging.

For instance, the very first widget A occupies the whole QMainWindow. The second one B opens in a tab first, so it's either

-----
| A |
-----

or

-----
| B |
-----

Then I drag the tab of B to (lets say) right area of QMainWindow - and get a vertical split like:

---------
| A | B |
---------

Then I open some other widget C. It again opens in a tab (lets say in left-and-top-most by default), so it's either

---------
| A | B |
---------

or

---------
| C | B |
---------

Now, I drag the tab of C to the bottom of B and get:

---------
|   | B |
  A -----
|   | C |
---------

Or if I would drag it to the bottom-middle of QMainWindow I would get:

---------
| A | B |
---------
|   C   |
---------

I hope you got the idea. If you are familiar with Eclipse it should be even easier to understand. The key point here is that I can do this infinitely many times and build absolutely customized layout, for example:

-----------------
|   | B | G |   |
| A ---------   |
|   | D |   | F |
--------- E |   |
|   C   |   |   |
-----------------
|       H       |
-----------------

This example looks messy, and the benefit of such crazy layout is of course questionable, but anyway, the question is - does Qt provide this behavior either out-of-the-box or at least some facilities to achieve it with minimal coding effort.

Kellene answered 4/1, 2013 at 1:27 Comment(1)
aka blender area layoutSouvaine
G
1

You probably want to look at enabling setDockNestingEnabled(bool) on your QMainWindow. This will give your docks the ability to split during drag and drop operations.

You could combine this with drag and drop support in other widgets like the tab widget.

Gumma answered 4/1, 2013 at 1:43 Comment(2)
link is gone. see Dock Widgets Example and QDockWidget Class. see also Qt-Advanced-Docking-SystemSouvaine
@Souvaine thanks. I've fixed the link for Qt6Gumma

© 2022 - 2024 — McMap. All rights reserved.