How to create a toggle button with slate?

How can I create a toggle button with slate?

By toggle button I mean a normal button which remains pressed after one click and returns normal after a second click (the style is toggled).

It seems that it can be done with SCheckbox, but I can’t understand how. Here is what I have tried:

            .Style(&FCoreStyle::Get().GetWidgetStyle< FCheckBoxStyle >("ToggleButton"))

I will show you how I implemented a toggle button with an image for an editor button. I know it isn’t directly answering your question, but hopefully it helps you find a way to do it.

During creation

			SAssignNew(MyToggleButton, SButton)
				.ButtonStyle(FEditorStyle::Get(), "ToggleButton")
				.OnClicked(this, &SMyClass::OnMyToggleButtonPressed)
					.Image(this, &SMyClass::GetMyToggleButtonBrush)

The function to get the brush

const FSlateBrush* SMyClass::GetMyToggleButtonBrush() const
	if (IsOn)
		return MyToggleButton->IsHovered() ? FEditorStyle::GetBrush("Level.MyToggleOnHighlightIcon16x") :
		return MyToggleButton->IsHovered() ? FEditorStyle::GetBrush("Level.MyToggleOnHighlightIcon16x") :

So what are you seeing when using the code in your question, and what do you expect to see instead?

I expected to have this: Redirecting… and I got something like the tool buttons of UE4 geometry mode (classic radio buttons, which are not good for tools). But I will try to do something like in the folliage mode (I’ll look at the source code).

Well I’m not sure how to do it from a coding perspective. But I’ve solved my button-image swapping issue using blueprints (maybe you can as well lol). It took some trial and error but the condition for the swap can be called based on an event dispatcher (which you may or may not need for your particular project.)

Hope this helps