# Cannot set background color to border in code

**URL:** <https://forums.unrealengine.com/t/cannot-set-background-color-to-border-in-code/433378>\
**Category:** UI\
**Tags:** unreal-engine, slate, UE4, CPP, question\
**Created:** [September 7, 2018, 3:07pm UTC](https://forums.unrealengine.com/t/cannot-set-background-color-to-border-in-code/433378 "2018-09-07T15:07:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vermond](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Vermond](https://forums.unrealengine.com/u/Vermond)\
**Post date:** [September 7, 2018, 3:07pm UTC](https://forums.unrealengine.com/t/cannot-set-background-color-to-border-in-code/433378/1 "2018-09-07T15:07:57Z")

</div>

I have tried many times as possible as I can.  
I wrote below code. Original is below link`s code.

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

```
	ChildSlot
		.VAlign(VAlign_Fill)
		.HAlign(HAlign_Fill)
		.Padding(FMargin(20))
		[
			SNew(SOverlay)
			+ SOverlay::Slot()
			.VAlign(VAlign_Bottom)
			.HAlign(HAlign_Right)
			.Padding(FMargin(20))
			[
				SNew(SBorder)
				.VAlign(VAlign_Center)
				.HAlign(HAlign_Center)
				.BorderBackgroundColor(FLinearColor(0, 1, 0, 1))
				.BorderImage(&brush)				
				.Padding(FMargin(20))
				[
					// Inside lies a text block with these settings
					SNew(STextBlock)
					.ShadowColorAndOpacity(FLinearColor::Black)
					.ColorAndOpacity(FLinearColor::Blue)
					.ShadowOffset(FIntPoint(-1, 1))
					.Font(FSlateFontInfo("Veranda", 16))
					// localized text to be translated with a generic name HelloSlateText
					.Text(LOCTEXT("HelloSlateText", "Hello, Slate!"))
				]
			]
		];

```

And result is this.

![253043-result1.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/5/7/b57db4dd52f1332d5a8bcf94ffa4fbe889dfd491.png)

Yes. There is no background color just transparent.

When I edited like this…

```
    				SNew(SBorder)
    				.VAlign(VAlign_Center)
    				.HAlign(HAlign_Center)
    				.BorderBackgroundColor(FLinearColor(0, 1, 0, 1))
    				//.BorderImage(&brush)				
    				.Padding(FMargin(20))

```

And result is…

![253046-rerult2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/3/9/739d5aab771ecf66d69ee86d51ba342ebc1aa8de.png)

See. Only border line has color. It`s not that I want. I want to fill color like working in UMG.

How can I fill color to background? Need any other option or something?

(I wrote this project at 4.20.2)

---

<div class="post-metadata">

**Author:** ![Vermond](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Vermond](https://forums.unrealengine.com/u/Vermond)\
**Post date:** [September 8, 2018, 5:22pm UTC](https://forums.unrealengine.com/t/cannot-set-background-color-to-border-in-code/433378/2 "2018-09-08T17:22:48Z")

</div>

I solved it. Check below link.

> **[Create a fBrush for Slate](https://forums.unrealengine.com/questions/421948/create-a-fbrush-for-slate.html)**
>
> Hi, I am attempting to use Slate to create a 50% alpha bar across the base of my screen. I have so far: ViewportWidget-\>AddSlot(20)\[ SNew(SOverlay) + SOverlay::Slot() .VAlign(VAlign\_Bottom)...

Declare FSlateBrush at header, not .cpp source file. And if you use it to fill background, color will apply with no problem

.h

```
//....
FSlateColorBrush brush = FSlateColorBrush(FLinearColor::Yellow);
//....

```

.cpp

```
SNew(SBorder)
    .VAlign(VAlign_Center)
    .HAlign(HAlign_Center)
    .BorderImage(&brush)  
//...

```

Result

![253141-answer.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/2/c/b2c3ff5dcc2407a11164f774d863858e22013c98.png)

Hope this helps who is trying to use slate in code.

---

<div class="post-metadata">

**Author:** ![Rushicpp](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rushicpp](https://forums.unrealengine.com/u/Rushicpp)\
**Post date:** [May 14, 2024, 2:57pm UTC](https://forums.unrealengine.com/t/cannot-set-background-color-to-border-in-code/433378/3 "2024-05-14T14:57:54Z")

</div>

> [@Vermond](#):
>
> `e(&brush)`

@Vermond I was facing the same issue.Thanks. It was really helpful.

---

<div class="post-metadata">

**Author:** ![dictateurfou](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dictateurfou](https://forums.unrealengine.com/u/dictateurfou)\
**Post date:** [June 1, 2024, 5:13am UTC](https://forums.unrealengine.com/t/cannot-set-background-color-to-border-in-code/433378/4 "2024-06-01T05:13:54Z")

</div>

This is an old subject but I want to clarify if anyone comes across this you can declare the color in C++ without having to put a property in the header

```c++
FSlateColorBrush* brushWhite = new FSlateColorBrush(FLinearColor(255, 255, 255, 1));

//And for call
SNew(SBorder)
    .BorderImage(brushWhite)

```
