如何在Qt Designer中管理QSplitter [英] 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?
从Qt示例本身开始:
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);
因此在此示例中,创建拆分器时没有任何对话框资源。如果必须用这种方式创建,那意味着我也必须在代码中创建所有控件,而不是Qt Creator。
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.
什么是正确的方法
推荐答案
您可以简单地在Qt Designer中创建包含项目的拆分器:
You can simply create splitter containing items in Qt Designer :
-
首先将小部件放置在对话框中或设计器中的小部件(它们不应处于布局中)
First place your widgets on your dialog or widget in designer (They should not be in a layout)
选择要放在拆分器中的小部件(按住CTL并单击它们)
Select the widgets that you want to be in a splitter (By holding CTL and clicking on them)
右键单击选定的小部件,然后从布局菜单中选择在Splitter中水平放置或在Splitter中垂直放置。
Right click on a selected widget and from Layout menu select Lay Out Horizontally in Splitter or Lay Out Vertically in Splitter.
现在将网格布局应用于对话框,一切都应该正常。您会在对象检查器视图中看到类似的内容:
Now apply a grid layout to the dialog and everything should be OK. You would see something like this in Object Inspector View :
这篇关于如何在Qt Designer中管理QSplitter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!