Cursor position relative to a widget element or left-top corner position of the widget

Hello,

How can I get mouse position relative to a widget element(that is, left-top corner of the widget is 0,0 - no matter where the widget is on the screen) in OnMouseOver event or left-top corner position of the widget(because then I can subtract mouse position and get what I want)?

For example: on the screenshot below I have widget consisting of the Vertical box which contains three elements: border, the widget of which I want the left-top location and another border.
Doesn’t matter which way the problem is resolved, blueprints or c++.

Greetings

If anyone is still interested, this can be achieved using this piece of code (I am using it inside NativeOnMouseMove function, but I reckon you can use this in blueprint or other function if you have geometry and mouseEvent)

FReply WidgetClass::NativeOnMouseMove(const FGeometry& geometry, const FPointerEvent& mouseEvent)
{
    const FVector2D localPosition = geometry.AbsoluteToLocal(mouseEvent.GetScreenSpacePosition());
    ....
}
1 Like