Child component in Introjucer


#1

Hi all,

As I figured out so far, the Introjucer does not include a native support to declare child components at design time.

Also the Groupbox does not act as a parent component neither as a concrete group of UI elements and, therefore every UI component we put in it, does not act as a child. 

As I saw, the only way to have a concrete group of UI elements is to go through the "New Introjucer Component/Jucer file" route.

My question is : Have I understood correctly or am I missing something ?

Thanks in advance

 

George  

 


#2

This is possible by using the “virtual class” field in the Introjucer. It is somewhat tedious and the introjucer won't give you the correct preview - but it works. Here is a quick step-by-step tutorial on how to do this starting with a new project:

1. Create a new “GUI Application” Introjucer project and immediately delete the MainComponent.cpp/MainComponent.h from the project. Right-click on the “Source” group and select “Add new GUI Component…” from the pop-up menu. Name your file “MainComponent” and - under the Class tab - rename the class to MainContentComponent. This will be your parent view and your application should now compile and just launch with an empty Window.

2. Now add a “New Group Box” child component to the MainContentComponent and change the “virtual class” field to “MyGroupBox

3. Now create a new GUI component MyGroupBox.cpp/MyGroupBox.h with “Add new GUI Component…”. In the Class tab of this component, make sure that “parent class” field is public GroupComponent, the “Constructor params” field is const String& name, const String & text and the “Member initializers” field is GroupComponent (name, text) You can add your subcomponents in the “Subcomponents” tab.

4. Change the background colour in “graphics” tab to be completely transparent. This will remove the fill operation in the paint method.

5. In the code tab, in the UserPrePaint section of the paint method add: GroupComponent::paint (g);

6. Compile and run your application

I hope this helps!


#3

That's right - you can edit nested components, but only if they're jucer comps, and not generic ones.


#4


Thanks a lot  for your detailed answer.
I will try it. 
I am trying  to develop a general-purpose procedure for controlling the mass-behavior of a group of UI elements based on only one parameter, the reference of the group component.

George