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"

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?

Product Version: Not Selected
Tags:
more ▼

asked Jan 11 '15 at 10:47 AM in C++ Programming

avatar image

envenger
423 77 118 148

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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?

more ▼

answered Jan 11 '15 at 01:06 PM

avatar image

Jamie Dale STAFF
7.5k 177 67 305

avatar image envenger Jan 11 '15 at 01:13 PM

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 https://answers.unrealengine.com/questions/157223/slate-cannot-detect-right-clicks.html

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
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