Qt - setting up an interface
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,开发者_StackOverflow 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.
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() )
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
ui.setupUi(this)
I'm not sure I perfectly understood your question, so feel free to provide details and I'll complete my answer.
精彩评论