How to create a UWidget programatically?

Hi everyone, this is my first question here!

I’ve been working with Unreal for a few weeks now, looking specifically at the UI systems.

I’m currently trying to create a dynamic radial menu system, that can be exposed to blueprints so designers can change paramaters such as menu radius, segment counts etc.

I would like to generate this through code, by creating and adding a new UButton (or custom subclass of UButton) to my user widget, however I can’t figure out how to do it.

This is some code to give you an idea of what I want to achieve:

void URadialMenuWidget::SynchronizeProperties()
{
	Super::SynchronizeProperties();

	if (SegmentContainer && SegmentCount > 0)
	{
		GenerateSegments();
	}
}

void URadialMenuWidget::GenerateSegments()
{
	Segments.Empty();
	const float SegmentAngle = 1/SegmentCount;

	for (int i = 0; i < SegmentCount; i++)
	{
		//Create a UButton and add to the widget tree here
	}
}

Is this possible or should I go about it a different way?

Cheers!