Dynamic grid layout with splitters
-
I have the need for a widget (that I will be using as the central widget of a
QMainWindow
) that allows me to drag-n-drop other widgets into it and arrange them in a grid layout. However, the sizes of the grid cells must be dynamic (like with aQSplitter
where you can resize the cells) and I need the ability to merge cells (like in a spreadsheet where you make a big cell or multiple smaller ones). Basically I want to give the user the ability to create a layout like this by only drag-n-drop interactions (each blue rectangle is aQWidget
):
Right now I am at the point where each of the widgets (the blue rectangles in the figure above) emit a signal that informs the received (theSplitArea
widget that I am trying to write) on which side of the widget (usingQt::Edge
) a new widget should be added.Is there anything that Qt gives me that I can use to simplify this task? The only Idea I have right now is to write a
SplitArea
widget that maintains a list of manyQSplitter
s and doing a lot of if- and switch-statements to arrange the objects. Should I even useQSplitter
s for this or better implement a customQLayout
class and somehow apply magic that allows to resize the layout by dragging the borders between the cells?I am thankful for any kind of suggestion on how to properly implement something like this.
-
@Joel-Bodenmann
if i got you correctly QMainWindow with QDockWidgets is really close to what you want to achieve -
@raven-worx Not at all. the
QMainWindow
only allows me to put but one "row" of widgets around the central widgets. My goal is to have a widget that arranges any number of widgets in any pattern as shown in my diagram, not just one row around a central widget.Also I want that to become the central widget of my main window. I am already using the dock widgets for other stuff ;)
-
@Joel-Bodenmann
ok.
I am afraid there is no (standard) ready Qt-provided solution for you.
Either you look for a 3rd party implementation or do it yourself. But i guess that it will be a lot of work. -
Thank you for your help, I appreciate it.
This will indeed result in a few nights worth of coding :P -
Hello @Joel-Bodenmann ,
I am interested in your idea, did you ahieve what you wanted.?
If so, did you use QSplitters.? -
@qtProgrammer Please excuse the late reply...
Yes I managed to get something up and running. It's a basic tiling window manager that uses
QSplitter
. What I have so far is working. You can put anyQWidget
at any place and resize the tiles with the mouse. However, drag'n'drop is not even close to finished.
As it's far from finished and not really well tested I decided not to share it. It's currently collecting dust sitting on my SSD. -
Hi
Even if not finished, it would still be super sample of how to use splitters in a clever way :) -
I'd be interested in that example as well,
I heard people saying that Splitter is not an alternate to layout but just a container. But a layout is nothing but a container with some nice control over how widgets are laid out. Why not splitter have the same advantage.? After trying to find more info on QSplitter, i can say that there's not much available except the surface level documenation. -
@Joel-Bodenmann Hi Joel, however unlikely as it may be, do you still have access to any of this code? Very curious how you implemented splitters inside the QGridLayout. If I understand correctly, you were able to drag widgets in order to expand/de-expand them using the QSplitters?
-
@russQt Well, this has been a long time ago... :D
I definitely had this working - I used it with at least some success back then.
Unfortunately, I did throw this code/project out last year when performing some housekeeping (getting rid of old stuff).I might still have it around on an old laptop. I'll check in the next few days and report back. But please don't keep your hopes up. Chances are slim.
-
@russQt I was digging hard but unfortunately I have no positive news for you. Sorry about that.
-