widgets are overlapping in main menu how to solve the problem in c++

i designed four widget in ue4 blueprint. my first widget is playing menu options i put one button in this widget i click the button it will go to the another widget and another widget has three buttons. That the three buttons are placed in 30% of the left side screen i click the first button the another widget will be come in another 70% of right screen and i click the second means its will also display the widget but the first button widget and second button widget the both widget are displayed how to remove the widget . i click the first widget button means its will display the first widget and i click the second button means its will display the widget in back side of the widget the first widget will be does not hidden. help to solve this problem

in .cpp

          void AJacobPlayerController::JoinGameMenu()
          {
       UE_LOG(LogTemp, Warning, TEXT("JacobPlayercontroller JoinGameMenu"));
       OnEnterState(AJoinGameMenuHUD::StaticClass(), false);

          }

in .h

            UFUNCTION(BlueprintCallable, Category = PlayerController)
	void JoinGameMenu();

            UPROPERTY()
	TSubclassOf<UUserWidget> MainWidgetClass;
        UPROPERTY()
	UUserWidget * MainWidget;

i put the widget in hud i put the coding below

in .h

   class MYPROJECT3_API AJoinGameMenuHUD : public AHUD
   {
GENERATED_BODY()
 protected:
UPROPERTY()
	TSubclassOf<UUserWidget> MainWidgetClass;
UPROPERTY()
	UUserWidget * MainWidget;

public:
AJoinGameMenuHUD();

};

in .cpp

      AJoinGameMenuHUD::AJoinGameMenuHUD()
       {
   static ConstructorHelpers::FObjectFinder<UObject>NewMainWidgetClass(TEXT("WidgetBlueprint'/Game/ThirdPerson/Widget/Server/JoinGameMenu.JoinGameMenu_C'"));
   MainWidgetClass = (UClass*)NewMainWidgetClass.Object;
   MainWidget = CreateWidget <UUserWidget>(GetWorld(), MainWidgetClass);

   if (MainWidget)
  {
	MainWidget->AddToViewport();
  }
 }

in join menu hud is the second button widget i created the first button that also the same coding

I’m not sure about the wisdom of trying to control the widgets via c++

If I’m following your post properly, my personal approach would be to use a Widget Switcher.

I’d go about creating individual widgets to hold the various panels, buttons, and Blueprint scripts for each.
I’d then use a “Master” or “Primary” Widget that would be your container for the whole system. With that “main” widget, I’d use a Widget Switcher component with your user created widgets as children to it.

You can then use BP scripts to bind click events to the sub widget buttons to change the active index value of your widget switcher component. You can include any visibility or placing logic with each click event as you see necessary.