How to manage QSplitter in Qt Designer

2020-02-08 23:49发布

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?

2条回答
Explosion°爆炸
2楼-- · 2020-02-09 00:31

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.

查看更多
Animai°情兽
3楼-- · 2020-02-09 00:39

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

查看更多
登录 后发表回答