Widget Creation (UserWidget)

So I found this blueprint template in this tutorial on creating widgets:

I’m wondering if theres anyone to do this in code. I have a pointer to my widget I create, and to the blueprint I create it from. Assigning it to the view port should be something like this:
GEngine->GameViewport->AddViewportWidgetContent(SNew(MyWidget));

I am also looking for a way call a function when the buttons are pressed.

Well I managed to spawn it. But yeah I still can’t add it to view port in the code. I created UZeltexWidget by extending UUserWidget class. Theres a button, when you create a widget that lets you reparent it from UserWidget to your custom one.

(in MyHud.h)

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Widgets)
TSubclassOf PlayScreenClass;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Widgets)
UZeltexWidget* PlayScreenWidget;

(in MyHud.cpp)

if (PlayScreenClass)
PlayScreenWidget = CreateWidget(GetWorld(), PlayScreenClass); // Spawns the custom widget