How to manage QSplitter in Qt Designer

When I press a button, I bring up a dialog where user select things and press 'Ok' at the end. I want a splitter in this dialog. Left pane will show tree and right will show something else. How do I do that right?

From Qt example itself:

 QSplitter *splitter = new QSplitter(parent);
 QListView *listview = new QListView;
 QTreeView *treeview = new QTreeView;
 QTextEdit *textedit = new QTextEdit;
 splitter->addWidget(listview);
 splitter->addWidget(treeview);
 splitter->addWidget(textedit);

So in this example, splitter is created without any dialog resource. If I have to create this way, that would mean I have to create all my controls in the code as well rather than Qt Creator.

What is the right way to do this when I need other controls on the screen?


You can simply create splitter containing items in Qt Designer :

  1. First place your widgets on your dialog or widget in designer (They should not be in a layout)

  2. Select the widgets that you want to be in a splitter (By holding CTL and clicking on them)

  3. Right click on a selected widget and from Layout menu select Lay Out Horizontally in Splitter or Lay Out Vertically in Splitter.

  4. Now apply a grid layout to the dialog and everything should be OK. You would see something like this in Object Inspector View :

enter image description here


Okay, I know this is ancient, but here's the complete answer.

First, within some sort of widget container, plop your pieces in. For the window I just did, I have a Widget as my window. I put two widgets inside that labeled something like topContainer and bottomContainer. I then put all the widgets they each need into them, and gave them their own layouts.

Then do NOT select the main container. Select the two widgets you want to split. You're in effect putting a splitter on them, not on the main container. So I went to the widget list window and selected both together, then right-click for the dialog window, scroll down to the Layout option, and "Lay Out Vertically in a Splitter" is NOT greyed out. Select it.

You still need a layout on the main container. A splitter is not a layout. So at that point, I just put a vertical layout on the main container.

To repeat: you are NOT setting a layout on the container holding the pieces you're trying to split. You are selecting the two widgets to split and adding a QSplitter around them. That's the trick to get it to work.


You can still create your controls in a .ui file using Qt Designer (integrated in Qt Creator). Within Qt Designer, add a QWidget object to your dialog. Then, from QDialog derived class you'll write, directly in your constructor, create your QSplitter using the QWidget object as a parent.

This way, you can create all but the splitter object from Qt Designer.

I think it's also possible to create the QSplitter (as you can create a QButton, QCheckBox...) item directly from Qt Designer.