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 a QSplitter 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 a QWidget):

    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 (the SplitArea widget that I am trying to write) on which side of the widget (using Qt::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 many QSplitters and doing a lot of if- and switch-statements to arrange the objects. Should I even use QSplitters for this or better implement a custom QLayout 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.


  • Moderators

    @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 ;)


  • Moderators

    @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 any QWidget 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.

    ScreenShot


  • Qt Champions 2016

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.