SButton how to set style by polling

Hi…

I want to know how to use the style of SButton by polling. I have a pointer to where the style has been stored and now I am using a function to set it but its showing me and error message.

.h
const FButtonStyle* GetItemIcon();

.cpp

const FButtonStyle* SItemWidget::GetItemIcon()
{
	if (InvStorage->Storage.Rows[SlotLoc.Get().RowNum].Columns[SlotLoc.Get().ColNum].ItemType == EItemType::StackableSingleConsumable)
	{
		int32 ItemIndex = InvStorage->Storage.Rows[SlotLoc.Get().RowNum].Columns[SlotLoc.Get().ColNum].ItemIndex;
		return(&InvStorage->StackableSingleFoodItemArray[ItemIndex].StackableSingleFoodItem.ItemIcon);
	}
	else
	{
		return(&InvStorage->EmptySlotImg);
	}
}

I am calling that function like this

			SNew(SButton)
			.HAlign(HAlign_Right)
			.VAlign(VAlign_Bottom)
			.ButtonStyle(this, &SItemWidget::GetItemIcon)

Seriously I have tried nearly every possible combination To achieve it… Or the button style cant be changed by anything?

ButtonStyle is a SLATE_STYLE_ARGUMENT, and arguments can’t be bound to delegates like attributes can (note: there is no SLATE_STYLE_ATTRIBTUE).

SButton does have a function to manually change the style (SButton::SetButtonStyle) which is what UMG uses when updating its button widgets, however I would only use that as an absolute last resort.

It seems you just want to update an image based upon the contents of a slot? A better way to do this, rather than messing with the style of the whole button, would probably be to put an SImage inside your SButton, and then bind the Image attribute to a delegate that returns the desired FSlateBrush*.

Does that sound like something that can work for your use-case?

Yup i figured it out and did something similar

		SNew(SButton)
		.HAlign(HAlign_Fill)
		.VAlign(VAlign_Fill)
		.ButtonStyle(&InvStorage->EmptySlotButtonStyle)
		.OnClicked(this, &SItemWidget::RightClick)
		.ContentPadding(FMargin(0))
		[
			SNew(SBorder)
			.Padding(FMargin(0, 0, 4.2, 2))
			.HAlign(HAlign_Right)
			.VAlign(VAlign_Bottom)
			.BorderImage(this, &SItemWidget::GetItemIcon)
			[
				SNew(STextBlock)
				.Font(InvStorage->StacksFont)
				.ColorAndOpacity(FSlateColor(FLinearColor(2.5, 0.5, 0.5)))
				.Text(this, &SItemWidget::GetNumOfStacks)
			]
		]

I plan on using some translucent images as SButton image when it is hover and all to add an outline…

Another related question to SButtons Slate cannot detect Right Clicks? - UI - Unreal Engine Forums