Qt - 设置界面
例如,我们可以在 Qt
中设置用户界面,如下所示:
Ui::Dialog ui;
ui.setupUi(dialog);
在这里,我将 dialog
的 UI 设置为 ui
。
但是,如果我写下以下内容:
setupUi(this)
这意味着什么?特别是我没有分配特定的用户界面(即 ui)。我将如何设置这样的界面?
谢谢。
We can for example set up a user interface in Qt
as follows:
Ui::Dialog ui;
ui.setupUi(dialog);
Here, I will setup the UI of dialog
to ui
.
But, if I write the following:
setupUi(this)
What does that mean? Especially that I'm not assigining a specific user interface (i.e; ui). How will I setup an interface that way?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
传递“dialog”和“this”之间的区别在于,当您传递“dialog”时,您在 Qt Designer 中创建的 UI 元素将按照您指定的方式放置在“dialog”小部件上,而当您传递“this”,UI 元素将放置在此小部件上(您调用 setupUi() 方法的小部件)
The difference between passing "dialog" and "this" is that when you pass "dialog", the UI elements that you created in Qt Designer will be put on "dialog" widget as you specify it to be put on, while when you pass "this", the UI elements will be put on this widget ( the widget from the method of which you're calling setupUi() )
命名空间 UI 由 UIC(ui 编译器)控制。基本上,UI 文件是 UI 内部的描述。要实例化它,您需要告诉它应该填充哪个小部件。在您的情况下,您明确告诉它填充“对话框”小部件。
如果您位于从 qwidget 派生的类中,那么当然,您可以使用
我不确定我是否完全理解您的问题,因此请随意提供详细信息,我将完成我的答案。
Namespace UI is controlled by the UIC (ui compiler). basically, a UI file is adescription of the internal of a UI. To instanciate it, you need to tell it which widget it's supposed to populate. In your case, you explicitely tell it to fill the "dialog" widget.
If you're inside a class derivating from qwidget, then of course, you can use
I'm not sure I perfectly understood your question, so feel free to provide details and I'll complete my answer.