How to Change Editabletext style with cpp in runtime

Hi, I would like to change the editable text widget (UEditableText) style with cpp during runtime.

The scenario is that the players can choose different configure sections then input their configuration through editable text widget; the text’s color shall change according to the player’s choice to remind them which section they are currently in.

What I have tried is something like this:

void MyClass::_configText(UEditableText* target, const FLinearColor& theColor, const FSlateFontInfo& theFont)
{
target->WidgetStyle.SetFont(theFont);
target->WidgetStyle.SetColorAndOpacity(FSlateColor(theColor));
target->SynchronizeProperties();

}

The problem is that, the value in UEditableText is changed but the new font and color is not shown on the screen.

I also found someone faced the same issue on the forum, “How to edit style of editableText in game ?”. It was posted over one year ago and seems not solved until now.

By the way, I also do the similar thing to UTextBlock like this:

void MyClass::_configText(UTextBlock* target, const FLinearColor& theColor, const FSlateFontInfo& theFont)
{
target->SetFont(theFont);
target->SetColorAndOpacity(FSlateColor(theColor));
}

This function works very well. What I want is some equivalent methods for UEditableText.

Hello! You can call RebuildWidget instead of SynchronizeProperties. The thing is that SynchronizeProperties is not refreshing Style )

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

	TAttribute<FText> TextBinding = PROPERTY_BINDING(FText, Text);
	TAttribute<FText> HintTextBinding = PROPERTY_BINDING(FText, HintText);

	MyEditableText->SetText(TextBinding);
	MyEditableText->SetHintText(HintTextBinding);
	MyEditableText->SetIsReadOnly(IsReadOnly);
	MyEditableText->SetIsPassword(IsPassword);
	MyEditableText->SetAllowContextMenu(AllowContextMenu);
	MyEditableText->SetVirtualKeyboardDismissAction(VirtualKeyboardDismissAction);
	MyEditableText->SetJustification(Justification);
	// TODO UMG Complete making all properties settable on SEditableText

	ShapedTextOptions.SynchronizeShapedTextProperties(*MyEditableText);
}

Hi, thanks for your reply. I tried RebuildWidget. The problem in my case is that Editabletext itself is not a UUserWidget but only a UWidget, so I can only call RebuildWidget at the parent widget class. Thus, it is wasteful as I need to rebuild the how widget tree for only one change; and it will make the logic very complicated (if not impossible) to change the build information(which is currently in a blueprint). Is there a method to rebuild the Editabletext only?

If you look at the UEditableText class, you can see that the WidgetStyle object is only used when the RebuildWidget function is called, as shown in the previous answer.
This means that updating the WidgetStyle variable does not actually cause any changes to the Slate object.
So I haven’t found a way to update the Style of the UEditableText at runtime as I want without changing the UEditableText class.
In my case, I only needed to change the font information out of the entire style, so my solution was to borrow the way a UTextBlock with a similar structure changes the font and add a custom class that inherits from UEditableText.
Of course, since I am working in a Blueprint environment, these additional class registrations were necessary, but If in a C++ environment, you may get the internal Slate widget with TakeWidget() and do the updates directly.
Here are the additional interfaces I registered

void UMyEditableText::SetFont(FSlateFontInfo InFont)
{
	if(!WidgetStyle.Font.IsIdenticalTo(InFont))
	{
		WidgetStyle.Font = InFont;
		if (MyEditableText.IsValid())
		{
			MyEditableText->SetFont(InFont);
			MyEditableText->Invalidate(EInvalidateWidgetReason::LayoutAndVolatility);
		}
	}
}

Hope this helps.