Slate cannot detect Right Clicks?

I find it wired that slate SButton cannot detect right clicks? I have gone through nearly everything but I can make right mouse buttons to work with slate.

This even only works with left clicks and not right clicks.

		.OnClicked(this, &SItemWidget::RightClick)

SButton is hard-coded to only respond to EKeys::LeftMouseButton (see SButton::OnMouseButtonDown and SButton::OnMouseButtonUp).

If you want a button that responds to a right click by calling OnClicked (which is weird, as that usually summons a context menu) you’ll have to make a custom widget to handle that (it could probably derive from SButton and override the functions listed above - check out SHyperlink for an example of how to correctly derive from SButton and call the base-class Construct function).

Actually, since you’ll have to pass the OnClicked handler through your custom widget regardless, you could also do this via composition.

You’d need to make a custom widget deriving from SCompoundWidget that contains an SButton, and then keep a hold of the OnClicked handler that you passed into the SButton so that you can call it from your own widget.

I had another idea to achieve it. I can detect when the SButton is hovered on and pass it to another place. Then I can detect when right click or left click is pressed through the inputs. Then if it is hovered and the right click is pressed as the same time, then trigger the function. Which would be more effective?

Another thing I thought of doing was extending from SBox like the SButton and copy pasting the SButton code. Except the OnClicked and replace it with OnLeftClicked and OnRightClicked.

Wont extending from SBoundary just like SButton and copy pasting the whole SButton code in it. Then replacing the OnClicked with OnLeftClicked and adding a new function similar to it with OnRightClicked be slightly more effective?

Sure, that would work fine too :slight_smile:

I got some errors while extending from SBorder.h
I did something exactly like SButton.h did(copy pasted the code while changing a few minor things like class name and stuff).

I got error in the SBorder.h class rather than my own class.

1>D:\Unreal Engine Launcher\4.6\Engine\Source\Runtime\Slate\Public\Widgets\Layout\SBorder.h(39): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>D:\Unreal Engine Launcher\4.6\Engine\Source\Runtime\Slate\Public\Widgets\Layout\SBorder.h(39): error C2143: syntax error : missing ',' before '&'
1>D:\Unreal Engine Launcher\4.6\Engine\Source\Runtime\Slate\Public\Widgets\Layout\SBorder.h(39): error C2653: 'FPointerEventHandler' : is not a class or namespace name
1>D:\Unreal Engine Launcher\4.6\Engine\Source\Runtime\Slate\Public\Widgets\Layout\SBorder.h(39): fatal error C1903: unable to recover from previous error(s); stopping compilation

Hmm, that is defined in SlateDelegates.h. What are you includes in SCustomItemButton.h and SCustomItemButton.cpp?

SButton.h for the .h file and
#include “SlateBasics.h”
#include “SCustomItemButton.h” for the cpp. Excluding the game name .h

I’ve just tried this in a test project and it worked fine.

It’s possibly an issue at the place where you’re including SCustomItemButton.h rather than SCustomItemButton itself (#includes can be fun like that).

Could you try adding #include "SlateDelegates.h" to SCustomItemButton.h - that should ensure the file has been included everywhere that’s using SCustomItemButton.

Alternatively, you could add #include "SlateBasics.h" to your projects PCH file (probably called WhateverYourProjectIsCalled.h unless you used a template when creating your project), since that will be included in everything too.