Make C++ Widget accessible with UMG editor

How do you make an accessible widget for blueprint in C++ ?

Here I’m creating my widget like that :

#PersoUserWidget.h

// The widget I want to be able to edit in the UMG editor.
 // Maybe a meta ?
 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Widgets")
 class UMyWidget * TheWidget;

#PersoUserWidget.cpp

TSharedRef<SWidget> UPersoUserWidget::RebuildWidget() {
	TSharedRef<SWidget> Widget = Super::RebuildWidget();

	UPanelWidget* RootWidget = Cast<UPanelWidget>(GetRootWidget());
	if (RootWidget && WidgetTree) {
		TheWidget = WidgetTree->ConstructWidget<UTheWidget>(UTheWidget::StaticClass());
		RootWidget->AddChild(TheWidget);
     }
    return Widget;
}

I want the widget editable as the CanvasPanel in default UUserWidget with UMG editor (The UserWidget inherits from UPersoUserWidget) :

But I can’t find where this canvas panel is declared. Maybe a UPROPERTY meta allows this use ?

Thanks.

You implmenting widget in wrong way. In order to understand whats doing on here you need to understand difference between UMG and Slate. Slate is UI framework build originally for editor, but can be used in game, but because all classes of Slate operate outside of UE4 reflection system so Slate can’t be used in blueprints. Thats why UMG was made, UMG is Slate wrapper for blueprint, yes UMG is not really UI framework on its own, just way to make Slate usable in blueprints with some extra features like animations and layout editor which Slate alone don’t have.

UWidget is Slate widget wrapper class, in RebuildWidget UMG expect you do define Slate widget (SWidget) and this is what you should do in RebuildWidget.

If you want to make widget that contains UMG widget, then you make UUserWidget with widget properties with this specifier:

UPROPERTY(meta = (BindWidget))

someone explained this well here:

If you ask me Slate is a lot easier to operate in C++ then using only UMG, so i think best option to do C++ widgets is to make UWidget (not UUserWidget as this class is made to contain other UMG widget, but if you use Slate you don’t use any other UMG widgets) and define slate widgets in RebuidWidget. You can read about slate here:

for example this will create simple text widget:

 TSharedRef<SWidget> UPersoWidget::RebuildWidget() {

     return SNew(STextBlock)
           .Text(FText::FromString("Example"));
 }

You also need to synchronize Slate widget with your UMG properties in SynchronizeProperties() function

But if you want to make base for Widget Blueprints then you should use BindWidget specifier method insted.