Hello. I’ve made a custom vertical box widget in C++ that I spawn programmatically and add to a scroll box widget through blueprints. Is there any way to add an OnMouseButtonDown event or something similar to it that extends to its whole area, or all the widgets inside of it? Here’s what the class looks like so far and it’s derived from a UHorizontalBox.
UCharSelectVerticalBox::UCharSelectVerticalBox()
{
static ConstructorHelpers::FObjectFinder<UFont> Meiryo(TEXT("Font'/Game/Fonts/Meiryo.Meiryo'"));
if(Meiryo.Succeeded() == false)
DebugMessage("Failed to load Meiryo font");
else
{
Typeface = Meiryo.Object;
}
TopBorder = NewObject<UBorder>();
BottomBorder = NewObject<UBorder>();
CharacterName = NewObject<UTextBlock>();
CharacterClass = NewObject<UTextBlock>();
LeftBorder1 = NewObject<UBorder>();
RightBorder1 = NewObject<UBorder>();
LeftBorder2 = NewObject<UBorder>();
RightBorder2 = NewObject<UBorder>();
HorizontalBox1 = NewObject<UHorizontalBox>();
HorizontalBox2 = NewObject<UHorizontalBox>();
FInfo.FontObject = Typeface;
FInfo.Size = 20;
}
UCharSelectVerticalBox::~UCharSelectVerticalBox()
{
}
void UCharSelectVerticalBox::Initialize(const FString &CharName, const FString &CharClass)
{
CharacterName->SetText(FText::FromString(CharName));
CharacterName->SetFont(FInfo);
CharacterClass->SetText(FText::FromString(CharClass));
CharacterClass->SetFont(FInfo);
HorizontalBox1->AddChild(LeftBorder1);
HorizontalBox1->AddChild(CharacterName);
HorizontalBox1->AddChild(RightBorder1);
UHorizontalBoxSlot *HorizontalBoxSlot1 = Cast<UHorizontalBoxSlot>(HorizontalBox1->GetSlots().Last());
HorizontalBoxSlot1->SetSize(FSlateChildSize(ESlateSizeRule::Fill));
HorizontalBoxSlot1->SetHorizontalAlignment(EHorizontalAlignment::HAlign_Right);
HorizontalBox2->AddChild(LeftBorder2);
HorizontalBox2->AddChild(CharacterClass);
HorizontalBox2->AddChild(RightBorder2);
UHorizontalBoxSlot *HorizontalBoxSlot2 = Cast<UHorizontalBoxSlot>(HorizontalBox2->GetSlots().Last());
HorizontalBoxSlot2->SetSize(FSlateChildSize(ESlateSizeRule::Fill));
HorizontalBoxSlot2->SetHorizontalAlignment(EHorizontalAlignment::HAlign_Right);
AddChild(TopBorder);
AddChild(HorizontalBox1);
AddChild(HorizontalBox2);
AddChild(BottomBorder);
}
void UCharSelectVerticalBox::Clicked()
{
DebugMessage("Would be great if I could do this");
}
And a screenshot of it in action:
Basically what I want to achieve is a mouse click event that triggers whenever you click anywhere on the white border or within it. Is it possible to overlay an invisible button with a higher z order or something without taking up any space in the scroll box or horizontal box widgets they’re in? Or can I actually add a mouse button event to the horizontal box? The latter would be preferred but I’m open to suggestions and any help is appreciated, thanks