# UMG RichTextBlock hyperlink / href markup

**URL:** <https://forums.unrealengine.com/t/umg-richtextblock-hyperlink-href-markup/454860>\
**Category:** UI\
**Tags:** unreal-engine, Widget, question, CPP, UMG\
**Created:** [September 4, 2019, 9:38pm UTC](https://forums.unrealengine.com/t/umg-richtextblock-hyperlink-href-markup/454860 "2019-09-04T21:38:23Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![anonymous\_user\_036d0123](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_036d0123](https://forums.unrealengine.com/u/anonymous_user_036d0123)\
**Post date:** [October 24, 2019, 1:21pm UTC](https://forums.unrealengine.com/t/umg-richtextblock-hyperlink-href-markup/454860/2 "2019-10-24T13:21:36Z")

</div>

create a .h file:

```
#include "CoreMinimal.h"
#include "Components/RichTextBlockDecorator.h"
#include "HyperLinkRichTextBlockDecorator.generated.h"

class FRichInlineHyperLinkDecorator : public FRichTextDecorator
{
public:
	FRichInlineHyperLinkDecorator(URichTextBlock* InOwner, UHyperLinkRichTextBlockDecorator* decorator);
	virtual bool Supports(const FTextRunParseResults& RunParseResult, const FString& Text) const override;
protected:
	virtual TSharedPtr<SWidget> CreateDecoratorWidget(const FTextRunInfo& RunInfo, const FTextBlockStyle& TextStyle) const override;
	FHyperlinkStyle linkstyle;
	FSimpleDelegate del;
	mutable FString idString;
};
//////////////////////////////////////////////////////////////////////////

UCLASS()
class MYTEST_API UHyperLinkRichTextBlockDecorator : public URichTextBlockDecorator
{
	GENERATED_BODY()
public:
	UHyperLinkRichTextBlockDecorator(const FObjectInitializer& ObjectInitializer);

	virtual TSharedPtr<ITextDecorator> CreateDecorator(URichTextBlock* InOwner) override;

	UPROPERTY(EditAnywhere, Category=Appearance)
	FHyperlinkStyle style;

	UFUNCTION(BlueprintNativeEvent)
	void ClickFun();
};

```

and a .cpp file:

```
#include "HyperLinkRichTextBlockDecorator.h"

#include <Components/RichTextBlock.h>
#include <SRichTextHyperlink.h>

FRichInlineHyperLinkDecorator::FRichInlineHyperLinkDecorator(URichTextBlock* InOwner, UHyperLinkRichTextBlockDecorator* decorator)
	: FRichTextDecorator(InOwner)
{
	linkstyle = decorator->style;
	del.BindLambda([=]() {
		decorator->ClickFun();
	});
}

bool FRichInlineHyperLinkDecorator::Supports(const FTextRunParseResults& RunParseResult, const FString& Text) const

{
	if (RunParseResult.Name == TEXT("a") && RunParseResult.MetaData.Contains(TEXT("id")))
	{
		const FTextRange& IdRange = RunParseResult.MetaData[TEXT("id")];
		idString = Text.Mid(IdRange.BeginIndex, IdRange.EndIndex - IdRange.BeginIndex);
		return true;
	}
	return false;
}

TSharedPtr<SWidget> FRichInlineHyperLinkDecorator::CreateDecoratorWidget(const FTextRunInfo& RunInfo, const FTextBlockStyle& TextStyle) const
{
	const bool bWarnIfMissing = true;

	TSharedPtr<FSlateHyperlinkRun::FWidgetViewModel> model = MakeShareable(new FSlateHyperlinkRun::FWidgetViewModel);

	TSharedPtr<SRichTextHyperlink> link = SNew(SRichTextHyperlink, model.ToSharedRef())
		.Text(FText::FromString("link"))
		.Style(&linkstyle)
		.OnNavigate(del);

	return link;
}

//////////////////////////////////////////////////////////////////////////

TSharedPtr<ITextDecorator> UHyperLinkRichTextBlockDecorator::CreateDecorator(URichTextBlock* InOwner)
{
	return MakeShareable(new FRichInlineHyperLinkDecorator(InOwner, this));
}

void UHyperLinkRichTextBlockDecorator::ClickFun_Implementation()
{
	if (GEngine) {
		GEngine->AddOnScreenDebugMessage(-1, 20, FColor::Red, "click link");
	}
}

UHyperLinkRichTextBlockDecorator::UHyperLinkRichTextBlockDecorator(const FObjectInitializer& ObjectInitializer)
	: Super(ObjectInitializer)
{
}

```

and then use this decorator to create a blueprint

![290998-tim图片20191024195615.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/3/d/73d1ad1a20d0dd873ee466938e55c1c095bbf9fd.png)

and then use this blueprint decorator like RichTextBlockImageDecorator:

 ![290999-tim图片20191024195816.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/3/3/7/337626e440e906a8e414997783fb08936d1d3f45.png)

good luck!

![291000-tim图片20191024200027.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/f/b/7fb2bb63ea0bb1c48e80c11b279be9f49d7fda79.png)

BTW,you can rewrite the click function in the blueprint and change the link style :

 ![291001-tim图片20191024200224.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/f/8/af8ec97b3e6ff96f574adaf63b6921c2c630ac3d.png)

---

_[View the full topic](https://forums.unrealengine.com/t/umg-richtextblock-hyperlink-href-markup/454860)._
