x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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:

  SNew(SCheckBox)
             .Style(&FCoreStyle::Get().GetWidgetStyle< FCheckBoxStyle >("ToggleButton"))
             [
                 SNew(STextBlock)
                 .Text(RadioText)
             ];
Product Version: UE 4.9
Tags:
more ▼

asked Oct 14 '15 at 03:44 PM in C++ Programming

avatar image

Arthur Masson
284 36 42 60

avatar image cavably Oct 14 '15 at 09:51 PM

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)
                 .ContentPadding(0)
                 .ButtonStyle(FEditorStyle::Get(), "ToggleButton")
                 .IsEnabled(true)
                 .OnClicked(this, &SMyClass::OnMyToggleButtonPressed)
                 .HAlign(HAlign_Center)
                 .VAlign(VAlign_Center)
                 .Content()
                 [
                     SNew(SImage)
                     .Image(this, &SMyClass::GetMyToggleButtonBrush)
                 ]

The function to get the brush

 const FSlateBrush* SMyClass::GetMyToggleButtonBrush() const
 {
     if (IsOn)
     {
         return MyToggleButton->IsHovered() ? FEditorStyle::GetBrush("Level.MyToggleOnHighlightIcon16x") :
             FEditorStyle::GetBrush("Level.MyToggleOnIcon16x");
     }
     else
     {
         return MyToggleButton->IsHovered() ? FEditorStyle::GetBrush("Level.MyToggleOnHighlightIcon16x") :
             FEditorStyle::GetBrush("Level.MyToggleOnIcon16x");
     }
 }
avatar image Jamie Dale STAFF Oct 15 '15 at 05:21 PM

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

avatar image Arthur Masson Oct 16 '15 at 08:06 AM

I expected to have this: http://getbootstrap.com/javascript/#buttons-checkbox-radio 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).

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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.)

alt text

Hope this helps

more ▼

answered Dec 21 '16 at 08:02 PM

avatar image

jluko
19 2 5 9

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question