I have an editable text box that displays an initial number to the user. I want to set the focus on that text box when it is created, then I want to do a “select all” (think CTRL+A) on the text that is displayed so that the user can immediately start typing and replace that number without having to backspace the initial number first. I know there is a “Set Focus” blueprint, but is there a function that can do the “Select All” text right after?
Nothing that I know of, but how about using hint text instead? You can set the initial text on the thing to be hint text that will disappear when the user begins typing.
Actually that’s a good idea. I think I’ll use that.
Set focus on the textbox in question off of any event you choose. In the case of this image it is doing so when anyone types anything, automatically allowing them to type in that field.
I found a solution in C++.
UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) class UEditableTextBox* MyEditableTextBox;
void UMyWidgetClass::SelectMyEditableTextBoxText() {
if (MyEditableTextBox) {
MyEditableTextBox->SetUserFocus(GetOwningPlayer());
FSlateApplication::Get().SetKeyboardFocus(MyEditableTextBox->TakeWidget());
FTimerHandle TimerHandle;
GetWorld()->GetTimerManager().SetTimer(TimerHandle, this, &UMyWidgetClass::SelectAllTextInTextBox, 0.3f, false);
}
}
void UMyWidgetClass::SelectAllTextInTextBox() {
if (MyEditableTextBox) {
TSharedRef EditBoxWidget = StaticCastSharedRef(MyEditableTextBox->TakeWidget());
EditBoxWidget->SelectAllText();
}
}
And you call SelectMyEditableTextBoxText() when you want to focus your UEditableTextBox and select all default text or text inside.
In my case it is for select the default text in case if user doesn’t want to enter a title himself when the UEditableTextBox appears.
I add a timer with 0.3 second delay and it works, if I try 0.1 or 0.2 second it doesn’t work and 0.5 second seems too long.