Search This Blog

Thursday, November 5, 2009

Qt, Understand The UI Designer

QtCreator uses a very cleaver way to separate the GUI part of your widget through
1. Composition
2. Namespace
(This two steps avoid the inheritance)

In essence,
1. The generated UI class can help generate all GUI-widgets for you (button, textline)
2. The generated UI class has a setupUi method (taking your non-gui widget as an argument),
and the method will use your non-gui widget as the single parent of all the auto-generated widgets. (very cleaver!)
3. In your non-gui widget constructor,
a. you generate a new UI class
b. call setupUi
4. but now, how do you refer to the auto-generated widgets created in the Ui class?
No problem! remember the Ui class is also a "member" of your non-gui widget.
5. So you can call connect, layout etc. to interact with your Ui class.
In the destructor of your non-gui widget, it can free the memory (delete ui) when your non-gui widget is dead or out of scope.

No comments: