Add child to C++ UUserWidget

WrapBox is a widget, so simply place
UWrapBox in it and then add items to
it.

I see, that’s sort of what I was coming to myself. You’re saying that UUserWidget isn’t really a widget itself (it has no look/feel, can’t have children etc.), it’s just a class that can hold widgets, and gets seen by Blueprint.
So just to help others who may come here: I create a UWrapBox member variable in my MaterialsBoxW class (call it root_widget), fill in that member variable by constructing a new UWrapBox. Something like this, in the overridden Initialize method:

root_widget = WidgetTree->ConstructWidget<UWrapBox>(UWrapBox::StaticClass(), TEXT("RootWidget"));
WidgetTree->RootWidget = root_widget;

and then add children to it by constructing them and using root_widget->AddChildWrapBox();.

And thanks for the pointer to investigate Slate (vs. UMG); I’ll check that out.

3 Likes