C++ 如何在 Qt Designer 中管理 QSplitter
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28309376/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to manage QSplitter in Qt Designer
提问by zar
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:
从 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);
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.
所以在这个例子中,splitter 是在没有任何对话框资源的情况下创建的。如果我必须以这种方式创建,那就意味着我必须在代码中创建所有控件,而不是 Qt Creator。
What is the right way to do this when I need other controls on the screen?
当我需要屏幕上的其他控件时,正确的方法是什么?
回答by Nejat
You can simply create splitter containing items in Qt Designer :
您可以简单地在 Qt Designer 中创建包含项目的拆分器:
First place your widgets on your dialog or widget in designer (They should not be in a layout)
Select the widgets that you want to be in a splitter (By holding CTL and clicking on them)
Right click on a selected widget and from Layoutmenu select Lay Out Horizontally in Splitteror 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 :
首先将您的小部件放在您的对话框或设计器中的小部件上(它们不应该在布局中)
选择要在拆分器中的小部件(按住 CTL 并单击它们)
右键单击选定的小部件,然后从布局菜单中选择在拆分器中水平布局或在拆分器中垂直布局。
现在将网格布局应用于对话框,一切都应该没问题。您会在 Object Inspector View 中看到类似的内容:
回答by jpo38
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.
您仍然可以使用 Qt Designer(集成在 Qt Creator 中)在 .ui 文件中创建控件。在 Qt Designer 中,QWidget
向对话框添加一个对象。然后,从 QDialog 派生类,您将直接在构造函数中编写,使用该QWidget
对象作为父对象创建 QSplitter 。
This way, you can create all but the splitter object from Qt Designer.
这样,您可以从 Qt Designer 创建除拆分器对象之外的所有对象。
I think it's also possible to create the QSplitter
(as you can create a QButton
, QCheckBox
...) item directly from Qt Designer.
我认为也可以直接从 Qt Designer创建QSplitter
(因为你可以创建一个QButton
,QCheckBox
...)项目。