Hi together,
I am trying to implement a WebBrowserWidget into my Editor Extension Plugin.
How can I properly use the “.OnUrlChanged” Event and bind my own function to it?
Here is my Widget:
void SoAuth2::Construct(const FArguments& InArgs)
{
TSharedRef<SVerticalBox> MainContent = SNew(SVerticalBox)
+ SVerticalBox::Slot()
[
//WebBrowserWidget
SNew(SWebBrowser)
.InitialURL(TEXT("https://www.google.com"))
.ShowControls(false)
.ShowAddressBar(false)
.ShowErrorMessage(true)
.SupportsTransparency(false)
.SupportsThumbMouseButtonNavigation(false)
.ShowInitialThrobber(true)
.PopupMenuMethod(TOptional<EPopupMethod>())
.ViewportSize(FVector2D::ZeroVector)
.OnUrlChanged()
];
ChildSlot
[
MainContent
];
}
It a delegate argument so you do it exact same way as any other delegate:
.OnUrlChanged(this, &SomeClass::SomeFunction)
First argument is object that event will call to, “this” means object that code is currently executing, so object you make widget in (not parent of widget, but where code is executed right now) you can put any object here (exceot UObjects, they need ot be biinded diffrenly), 2nd is function pointer of function that gonna be called.
Function you bind you needs to match to delegate with arguments and return type, you can check that by looking api refrence, go to delegate variable (Slate widget FArguments):
And click the type of delegate FOnTextChanged:
typedef TBaseDelegate_OneParam< void, const FText & > FOnTextChanged;
From template arguments oyu can deduce that function should not return anything (void) and need to have 1 argument
of type const FText &, so function you bind to need declared like this:
void SomeFunction(const FText &);
You can also bind delegate to delegate of same type
Hi ,
you are a life saver!
Seriously, I din’t expect it to be that easy! I was trying around with declaring my own delegates and whatever…
For a test I printed to console:
void SoAuth2::Construct(const FArguments& InArgs)
{
TSharedRef<SVerticalBox> MainContent = SNew(SVerticalBox)
+ SVerticalBox::Slot()
[
//WebBrowserWidget
SNew(SWebBrowser)
.InitialURL(TEXT("https://www.google.com"))
.ShowControls(false)
.ShowAddressBar(false)
.ShowErrorMessage(true)
.SupportsTransparency(false)
.SupportsThumbMouseButtonNavigation(false)
.ShowInitialThrobber(true)
.PopupMenuMethod(TOptional<EPopupMethod>())
.ViewportSize(FVector2D::ZeroVector)
.OnUrlChanged(this, &SoAuth2::HandleOnUrlChangedOAuth)
];
ChildSlot
[
MainContent
];
}
//My function
void SoAuth2::HandleOnUrlChangedOAuth(const FText & Text)
{
UE_LOG(LogTemp, Warning, TEXT("The link finally changed baaaaam!!"));
}