Populate UMG Widget dynamically from C++

You can just use NewObject to create the widget and then add it as a child to a panel widget, there are many types of panel widget (canvas panel, scroll box, vertical box, etc.) and most of them has their own specific way to add child, so you might want to look it up in the API document:

Now for you particular case, assuming that the scroll box that you have created is exposed as variable with the name “MyScrollBox” and that you are using a vertical box inside of it to arrange your item widgets then the code would be something like this (note that I write this code without trying it, it’s not even written in a proper c++ text editor, I only wanted to show you how it’s done in c++) :

UCLASS()
class UMyInventoryWidget : UUserWidget
{
	GENERATED_BODY()

	UPROPERTY()
	UVerticalBox* ItemWidgetsBox;

	virtual void NativeConstruct() override
	{
		Super::NativeConstruct();

		if ( UScrollBox* ScrollBox = Cast<UScrollBox>( GetWidgetFromName("MyScrollBox") ) )
		{
			ItemWidgetsBox = NewObject<UVerticalBox>();
			ScrollBox->AddChild( ItemWidgetsBox );
		}
		else
		{
			// Can't find the scroll widget, wrong name maybe, or a widget with that name is not a scrollwidget
			ItemWidgetsBox = nullptr;
		}		
	}

	UFUNCTION(BlueprintCallable)
	void SetItems( const TArray<UItem*>& Items )
	{
		static FMargin Padding( 5 );

		if ( !ItemWidgetsBox )
		{
			return;
		}

		ItemWidgetsBox->ClearChildren();
		
		for ( UItem* Item : Items )
		{
			UItemWidget* ItemWidget = NewObject<UItemWidget>();
			ItemWidget->SetItem( Item );

			UVerticalBoxSlot* Slot = ItemWidgetsBox->AddChildToVerticalBox( ItemWidget );
			Slot->SetPadding( Padding );
		}
	}

};